mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
增大服务最大容纳的定时器数
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
|
|
||||||
var closeSig chan bool
|
var closeSig chan bool
|
||||||
var timerDispatcherLen = 10000
|
var timerDispatcherLen = 100000
|
||||||
|
|
||||||
type IService interface {
|
type IService interface {
|
||||||
Init(iService IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{})
|
Init(iService IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{})
|
||||||
|
|||||||
@@ -65,23 +65,26 @@ func StartTimer(minTimerInterval time.Duration,maxTimerNum int){
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tickRoutine(minTimerInterval time.Duration){
|
func tickRoutine(minTimerInterval time.Duration){
|
||||||
|
var bContinue bool
|
||||||
for{
|
for{
|
||||||
time.Sleep(minTimerInterval)
|
bContinue = tick()
|
||||||
tick()
|
if bContinue == false {
|
||||||
|
time.Sleep(minTimerInterval)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tick(){
|
func tick() bool{
|
||||||
now := Now()
|
now := Now()
|
||||||
timerHeapLock.Lock()
|
timerHeapLock.Lock()
|
||||||
if timerHeap.Len() <= 0 { // 没有任何定时器,立刻返回
|
if timerHeap.Len() <= 0 { // 没有任何定时器,立刻返回
|
||||||
timerHeapLock.Unlock()
|
timerHeapLock.Unlock()
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
nextFireTime := timerHeap.timers[0].fireTime
|
nextFireTime := timerHeap.timers[0].fireTime
|
||||||
if nextFireTime.After(now) { // 没有到时间的定时器,返回
|
if nextFireTime.After(now) { // 没有到时间的定时器,返回
|
||||||
timerHeapLock.Unlock()
|
timerHeapLock.Unlock()
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
t := heap.Pop(&timerHeap).(*Timer)
|
t := heap.Pop(&timerHeap).(*Timer)
|
||||||
@@ -89,10 +92,11 @@ func tick(){
|
|||||||
if len(t.C)>= cap(t.C) {
|
if len(t.C)>= cap(t.C) {
|
||||||
log.Error("Timer channel full!")
|
log.Error("Timer channel full!")
|
||||||
|
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
t.C <- t
|
t.C <- t
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func Now() time.Time{
|
func Now() time.Time{
|
||||||
|
|||||||
Reference in New Issue
Block a user