From c373979c09db892d5d1d8e35ff32fee0543ab6dc Mon Sep 17 00:00:00 2001 From: Leavrth Date: Thu, 22 Feb 2024 13:40:19 +0800 Subject: [PATCH 1/4] avoid to updateCounts frequently Signed-off-by: Leavrth --- pkg/schedule/operator/operator_controller.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/schedule/operator/operator_controller.go b/pkg/schedule/operator/operator_controller.go index baef0c6d564..bf7126a27aa 100644 --- a/pkg/schedule/operator/operator_controller.go +++ b/pkg/schedule/operator/operator_controller.go @@ -486,6 +486,7 @@ func (oc *Controller) addOperatorLocked(op *Operator) bool { return false } oc.operators[regionID] = op + oc.counts[op.SchedulerKind()]++ operatorCounter.WithLabelValues(op.Desc(), "start").Inc() operatorSizeHist.WithLabelValues(op.Desc()).Observe(float64(op.ApproximateSize)) opInfluence := NewTotalOpInfluence([]*Operator{op}, oc.cluster) @@ -505,7 +506,6 @@ func (oc *Controller) addOperatorLocked(op *Operator) bool { storeLimitCostCounter.WithLabelValues(strconv.FormatUint(storeID, 10), n).Add(float64(stepCost) / float64(storelimit.RegionInfluence[v])) } } - oc.updateCounts(oc.operators) var step OpStep if region := oc.cluster.GetRegion(op.RegionID()); region != nil { @@ -602,7 +602,7 @@ func (oc *Controller) removeOperatorLocked(op *Operator) bool { regionID := op.RegionID() if cur := oc.operators[regionID]; cur == op { delete(oc.operators, regionID) - oc.updateCounts(oc.operators) + oc.counts[op.SchedulerKind()]-- operatorCounter.WithLabelValues(op.Desc(), "remove").Inc() oc.ack(op) if op.Kind()&OpMerge != 0 { @@ -862,7 +862,7 @@ func (oc *Controller) SetOperator(op *Operator) { oc.Lock() defer oc.Unlock() oc.operators[op.RegionID()] = op - oc.updateCounts(oc.operators) + oc.counts[op.SchedulerKind()]++ } // OpWithStatus records the operator and its status. From d2c588bdeadbcf329031e7f29fb7abe3f5ca0ac1 Mon Sep 17 00:00:00 2001 From: Leavrth Date: Thu, 22 Feb 2024 14:24:01 +0800 Subject: [PATCH 2/4] add more timeout for scatter-regions Signed-off-by: Leavrth --- pkg/schedule/operator/operator.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/schedule/operator/operator.go b/pkg/schedule/operator/operator.go index b87a050969f..ceded6b2b54 100644 --- a/pkg/schedule/operator/operator.go +++ b/pkg/schedule/operator/operator.go @@ -99,6 +99,10 @@ func NewOperator(desc, brief string, regionID uint64, regionEpoch *metapb.Region for _, v := range steps { maxDuration += v.Timeout(approximateSize).Seconds() } + if desc == "scatter-region" { + // set an hour + maxDuration = 3600 + } return &Operator{ desc: desc, brief: brief, From 8fd99e833cd48603d2696d8c8be110ed4aa706be Mon Sep 17 00:00:00 2001 From: Leavrth Date: Wed, 28 Feb 2024 15:21:52 +0800 Subject: [PATCH 3/4] remove timeout for debug Signed-off-by: Leavrth --- pkg/schedule/operator/operator.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/schedule/operator/operator.go b/pkg/schedule/operator/operator.go index ceded6b2b54..b87a050969f 100644 --- a/pkg/schedule/operator/operator.go +++ b/pkg/schedule/operator/operator.go @@ -99,10 +99,6 @@ func NewOperator(desc, brief string, regionID uint64, regionEpoch *metapb.Region for _, v := range steps { maxDuration += v.Timeout(approximateSize).Seconds() } - if desc == "scatter-region" { - // set an hour - maxDuration = 3600 - } return &Operator{ desc: desc, brief: brief, From 05e225705d6a482abb245b44c159987a076459f4 Mon Sep 17 00:00:00 2001 From: Leavrth Date: Thu, 29 Feb 2024 13:56:13 +0800 Subject: [PATCH 4/4] remove updatecounts Signed-off-by: Leavrth --- pkg/schedule/operator/operator_controller.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pkg/schedule/operator/operator_controller.go b/pkg/schedule/operator/operator_controller.go index bf7126a27aa..07cafb9c566 100644 --- a/pkg/schedule/operator/operator_controller.go +++ b/pkg/schedule/operator/operator_controller.go @@ -560,6 +560,7 @@ func (oc *Controller) removeOperatorsLocked() []*Operator { var removed []*Operator for regionID, op := range oc.operators { delete(oc.operators, regionID) + oc.counts[op.SchedulerKind()]-- operatorCounter.WithLabelValues(op.Desc(), "remove").Inc() oc.ack(op) if op.Kind()&OpMerge != 0 { @@ -567,7 +568,6 @@ func (oc *Controller) removeOperatorsLocked() []*Operator { } removed = append(removed, op) } - oc.updateCounts(oc.operators) return removed } @@ -783,16 +783,6 @@ func (oc *Controller) GetHistory(start time.Time) []OpHistory { return history } -// updateCounts updates resource counts using current pending operators. -func (oc *Controller) updateCounts(operators map[uint64]*Operator) { - for k := range oc.counts { - delete(oc.counts, k) - } - for _, op := range operators { - oc.counts[op.SchedulerKind()]++ - } -} - // OperatorCount gets the count of operators filtered by kind. // kind only has one OpKind. func (oc *Controller) OperatorCount(kind OpKind) uint64 {