mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
lib/storage: tune updating a map with today`s metric ids
- Increase update iterval from 1s to 10s. This should reduce CPU usage for large amounts of metric ids with constant churn. - Reduce pendingTodayMetricIDsLock lock duration during the update.
This commit is contained in:
parent
e27fd5148a
commit
a2986cde70
1 changed files with 9 additions and 7 deletions
|
@ -360,15 +360,17 @@ func (s *Storage) startTodayMetricIDsUpdater() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var todayMetricIDsUpdateInterval = time.Second * 10
|
||||||
|
|
||||||
func (s *Storage) todayMetricIDsUpdater() {
|
func (s *Storage) todayMetricIDsUpdater() {
|
||||||
t := time.NewTimer(time.Second)
|
t := time.NewTimer(todayMetricIDsUpdateInterval)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.stop:
|
case <-s.stop:
|
||||||
return
|
return
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
s.updateTodayMetricIDs()
|
s.updateTodayMetricIDs()
|
||||||
t.Reset(time.Second)
|
t.Reset(todayMetricIDsUpdateInterval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -766,20 +768,20 @@ func (s *Storage) updateTodayMetricIDs() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slow path tm.m must be updated with non-empty s.pendingTodayMetricIDs.
|
// Slow path: tm.m must be updated with non-empty s.pendingTodayMetricIDs.
|
||||||
m := make(map[uint64]struct{}, len(tm.m)+newMetricIDsLen)
|
m := make(map[uint64]struct{}, len(tm.m)+newMetricIDsLen)
|
||||||
if tm.date == today {
|
if tm.date == today {
|
||||||
for metricID := range tm.m {
|
for metricID := range tm.m {
|
||||||
m[metricID] = struct{}{}
|
m[metricID] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pendingTodayMetricIDsLock.Lock()
|
s.pendingTodayMetricIDsLock.Lock()
|
||||||
for metricID := range s.pendingTodayMetricIDs {
|
newMetricIDs := s.pendingTodayMetricIDs
|
||||||
|
s.pendingTodayMetricIDs = make(map[uint64]struct{}, len(newMetricIDs))
|
||||||
|
s.pendingTodayMetricIDsLock.Unlock()
|
||||||
|
for metricID := range newMetricIDs {
|
||||||
m[metricID] = struct{}{}
|
m[metricID] = struct{}{}
|
||||||
}
|
}
|
||||||
s.pendingTodayMetricIDs = make(map[uint64]struct{}, len(s.pendingTodayMetricIDs))
|
|
||||||
s.pendingTodayMetricIDsLock.Unlock()
|
|
||||||
|
|
||||||
tmNew := &todayMetricIDs{
|
tmNew := &todayMetricIDs{
|
||||||
m: m,
|
m: m,
|
||||||
|
|
Loading…
Reference in a new issue