mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
lib/storage: check for prevHourMetricIDs cache before falling back to checking for (date, metricID) entries during data ingestion
This should reduce possible CPU usage spikes at the beginning of every hour. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1046
This commit is contained in:
parent
8e5dad8483
commit
c6a7288109
@ -1659,6 +1659,8 @@ func (s *Storage) updatePerDateData(rows []rawRow) error {
|
||||
prevMetricID uint64
|
||||
)
|
||||
hm := s.currHourMetricIDs.Load().(*hourMetricIDs)
|
||||
hmPrev := s.prevHourMetricIDs.Load().(*hourMetricIDs)
|
||||
hmPrevDate := hmPrev.hour / 24
|
||||
nextDayMetricIDs := &s.nextDayMetricIDs.Load().(*byDateMetricIDEntry).v
|
||||
todayShare16bit := uint64((float64(fasttime.UnixTimestamp()%(3600*24)) / (3600 * 24)) * (1 << 16))
|
||||
type pendingDateMetricID struct {
|
||||
@ -1708,6 +1710,10 @@ func (s *Storage) updatePerDateData(rows []rawRow) error {
|
||||
}
|
||||
s.pendingHourEntries = append(s.pendingHourEntries, e)
|
||||
s.pendingHourEntriesLock.Unlock()
|
||||
if date == hmPrevDate && hmPrev.m.Has(metricID) {
|
||||
// The metricID is already registered for the current day on the previous hour.
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Slower path: check global cache for (date, metricID) entry.
|
||||
|
Loading…
Reference in New Issue
Block a user