diff --git a/service/service.go b/service/service.go index 2fd98ab..ff45f33 100644 --- a/service/service.go +++ b/service/service.go @@ -15,7 +15,7 @@ import ( var closeSig chan bool -var timerDispatcherLen = 10000 +var timerDispatcherLen = 100000 type IService interface { Init(iService IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{}) diff --git a/util/timer/heap.go b/util/timer/heap.go index 05ada2a..d796f1d 100644 --- a/util/timer/heap.go +++ b/util/timer/heap.go @@ -65,23 +65,26 @@ func StartTimer(minTimerInterval time.Duration,maxTimerNum int){ } func tickRoutine(minTimerInterval time.Duration){ + var bContinue bool for{ - time.Sleep(minTimerInterval) - tick() + bContinue = tick() + if bContinue == false { + time.Sleep(minTimerInterval) + } } } -func tick(){ +func tick() bool{ now := Now() timerHeapLock.Lock() if timerHeap.Len() <= 0 { // 没有任何定时器,立刻返回 timerHeapLock.Unlock() - return + return false } nextFireTime := timerHeap.timers[0].fireTime if nextFireTime.After(now) { // 没有到时间的定时器,返回 timerHeapLock.Unlock() - return + return false } t := heap.Pop(&timerHeap).(*Timer) @@ -89,10 +92,11 @@ func tick(){ if len(t.C)>= cap(t.C) { log.Error("Timer channel full!") - return + return true } t.C <- t + return true } func Now() time.Time{