Skip to content

Commit

Permalink
Move checkIdle out of critical getTaskPump
Browse files Browse the repository at this point in the history
  • Loading branch information
vancexu committed Jun 29, 2018
1 parent 9427a6a commit aea2c88
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions service/matching/taskListManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (c *taskListManagerImpl) Start() error {
c.taskWriter.Start()
c.signalNewTask()
go c.getTasksPump()
go c.checkIdle()

return nil
}
Expand Down Expand Up @@ -738,13 +739,35 @@ deliverBufferTasksLoop:
}
}

func (c *taskListManagerImpl) checkIdle() {
checkIdleTaskListTimer := time.NewTimer(c.config.IdleTasklistCheckInterval())

checkIdleLoop:
for {
select {
case <-c.shutdownCh:
break checkIdleLoop
case <-checkIdleTaskListTimer.C:
{
pollers := c.GetAllPollerInfo()
if len(pollers) == 0 && !c.isTaskAddedRecently() {
c.Stop()
break checkIdleLoop
}
checkIdleTaskListTimer = time.NewTimer(c.config.IdleTasklistCheckInterval())
}
}
}

checkIdleTaskListTimer.Stop()
}

func (c *taskListManagerImpl) getTasksPump() {
defer close(c.taskBuffer)
c.startWG.Wait()

go c.deliverBufferTasksForPoll()
updateAckTimer := time.NewTimer(c.config.UpdateAckInterval())
checkIdleTaskListTimer := time.NewTimer(c.config.IdleTasklistCheckInterval())
getTasksPumpLoop:
for {
select {
Expand Down Expand Up @@ -798,19 +821,10 @@ getTasksPumpLoop:
c.signalNewTask() // periodically signal pump to check persistence for tasks
updateAckTimer = time.NewTimer(c.config.UpdateAckInterval())
}
case <-checkIdleTaskListTimer.C:
{
pollers := c.GetAllPollerInfo()
if len(pollers) == 0 && !c.isTaskAddedRecently() {
c.Stop()
}
checkIdleTaskListTimer = time.NewTimer(c.config.IdleTasklistCheckInterval())
}
}
}

updateAckTimer.Stop()
checkIdleTaskListTimer.Stop()
}

// Retry operation on transient error and on rangeID change. On rangeID update by another process calls c.Stop().
Expand Down

0 comments on commit aea2c88

Please sign in to comment.