From 6494b2282bbcd9238cd512abc6adc6b8c6722e5d Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 18 Apr 2024 18:38:48 +0800 Subject: [PATCH] speed up checkSuspectRegions and checkWaitingRegions Signed-off-by: lhy1024 --- pkg/schedule/coordinator.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index 15d734c25397..24c84b352677 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -194,9 +194,9 @@ func (c *Coordinator) PatrolRegions() { // Check priority regions first. c.checkPriorityRegions() // Check suspect regions first. - c.checkSuspectRegions() + c.checkSuspectRegions(regionChan) // Check regions in the waiting list - c.checkWaitingRegions() + c.checkWaitingRegions(regionChan) // Avoid to check the same regions repeatedly. if len(key) == 0 && len(regionChan) != 0 { @@ -255,19 +255,39 @@ func (c *Coordinator) isSchedulingHalted() bool { return c.cluster.GetSchedulerConfig().IsSchedulingHalted() } -func (c *Coordinator) checkSuspectRegions() { +func (c *Coordinator) checkSuspectRegions(regionChan chan *core.RegionInfo) { for _, id := range c.checkers.GetSuspectRegions() { region := c.cluster.GetRegion(id) - c.tryAddOperators(region) + regionChan <- region + } + for { + select { + case <-c.ctx.Done(): + return + default: + if len(regionChan) == 0 { + return + } + } } } -func (c *Coordinator) checkWaitingRegions() { +func (c *Coordinator) checkWaitingRegions(regionChan chan *core.RegionInfo) { items := c.checkers.GetWaitingRegions() waitingListGauge.Set(float64(len(items))) for _, item := range items { region := c.cluster.GetRegion(item.Key) - c.tryAddOperators(region) + regionChan <- region + } + for { + select { + case <-c.ctx.Done(): + return + default: + if len(regionChan) == 0 { + return + } + } } }