Skip to content

Commit 71e8185

Browse files
authored
resource manager: only record active resource group metrics (tikv#404)
Signed-off-by: disksing <i@disksing.com>
1 parent a6b8537 commit 71e8185

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

pkg/mcs/resourcemanager/server/manager.go

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,15 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context, pushMetricsAddr st
486486
}
487487
case <-availableRUTicker.C:
488488
m.RLock()
489-
groups := make([]*ResourceGroup, 0, len(m.groups))
490-
for name, group := range m.groups {
491-
if name == reservedDefaultGroupName {
489+
groups := make([]*ResourceGroup, 0, len(m.consumptionRecord))
490+
for r := range m.consumptionRecord {
491+
if r.name == reservedDefaultGroupName {
492492
continue
493493
}
494-
groups = append(groups, group)
494+
group, ok := m.groups[r.name]
495+
if ok {
496+
groups = append(groups, group)
497+
}
495498
}
496499
m.RUnlock()
497500
// prevent many groups and hold the lock long time.
@@ -507,37 +510,28 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context, pushMetricsAddr st
507510
}
508511
case <-recordMaxTicker.C:
509512
// Record the sum of RRU and WRU every second.
510-
m.RLock()
511-
names := make([]string, 0, len(m.groups))
512-
for name := range m.groups {
513-
names = append(names, name)
514-
}
515-
m.RUnlock()
516-
for _, name := range names {
517-
if t, ok := maxPerSecTrackers[name]; !ok {
518-
maxPerSecTrackers[name] = newMaxPerSecCostTracker(name, defaultCollectIntervalSec)
519-
} else {
520-
t.FlushMetrics()
521-
}
513+
for _, t := range maxPerSecTrackers {
514+
t.FlushMetrics()
522515
}
523516

524517
case <-rcuTicker.C:
525518
m.RLock()
526-
names := make([]string, 0, len(m.groups))
527-
fillRates := make([]float64, 0, len(m.groups))
528-
for name, group := range m.groups {
519+
names := make([]string, 0, len(rcuTrackers))
520+
fillRates := make([]float64, 0, len(rcuTrackers))
521+
for name := range rcuTrackers {
529522
if name == reservedDefaultGroupName {
530523
continue
531524
}
532-
names = append(names, name)
533-
fillRates = append(fillRates, group.getFillRate())
525+
group, ok := m.groups[name]
526+
if ok {
527+
names = append(names, name)
528+
fillRates = append(fillRates, group.getFillRate())
529+
}
534530
}
535531
cpuMsCost := m.controllerConfig.RequestUnit.CPUMsCost
536532
m.RUnlock()
537533
for i, name := range names {
538-
if t, ok := rcuTrackers[name]; ok {
539-
t.FlushMetrics(fillRates[i], cpuMsCost)
540-
}
534+
rcuTrackers[name].FlushMetrics(fillRates[i], cpuMsCost)
541535
}
542536

543537
case <-pushMetricsTickerC:

0 commit comments

Comments
 (0)