mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
lib/streamaggr: reduce the number of pointers at "total" aggregation state
This should reduce load on GC when scanning heap objects.
This commit is contained in:
parent
d42667fc41
commit
b232968bb4
1 changed files with 3 additions and 6 deletions
|
@ -34,7 +34,7 @@ type totalAggrState struct {
|
||||||
|
|
||||||
type totalStateValue struct {
|
type totalStateValue struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
lastValues map[string]*lastValueState
|
lastValues map[string]lastValueState
|
||||||
total float64
|
total float64
|
||||||
deleteDeadline uint64
|
deleteDeadline uint64
|
||||||
deleted bool
|
deleted bool
|
||||||
|
@ -74,7 +74,7 @@ func (as *totalAggrState) pushSamples(samples []pushSample) {
|
||||||
if !ok {
|
if !ok {
|
||||||
// The entry is missing in the map. Try creating it.
|
// The entry is missing in the map. Try creating it.
|
||||||
v = &totalStateValue{
|
v = &totalStateValue{
|
||||||
lastValues: make(map[string]*lastValueState),
|
lastValues: make(map[string]lastValueState),
|
||||||
}
|
}
|
||||||
vNew, loaded := as.m.LoadOrStore(outputKey, v)
|
vNew, loaded := as.m.LoadOrStore(outputKey, v)
|
||||||
if loaded {
|
if loaded {
|
||||||
|
@ -87,10 +87,6 @@ func (as *totalAggrState) pushSamples(samples []pushSample) {
|
||||||
deleted := sv.deleted
|
deleted := sv.deleted
|
||||||
if !deleted {
|
if !deleted {
|
||||||
lv, ok := sv.lastValues[inputKey]
|
lv, ok := sv.lastValues[inputKey]
|
||||||
if !ok {
|
|
||||||
lv = &lastValueState{}
|
|
||||||
sv.lastValues[inputKey] = lv
|
|
||||||
}
|
|
||||||
if ok || keepFirstSample {
|
if ok || keepFirstSample {
|
||||||
if s.value >= lv.value {
|
if s.value >= lv.value {
|
||||||
sv.total += s.value - lv.value
|
sv.total += s.value - lv.value
|
||||||
|
@ -101,6 +97,7 @@ func (as *totalAggrState) pushSamples(samples []pushSample) {
|
||||||
}
|
}
|
||||||
lv.value = s.value
|
lv.value = s.value
|
||||||
lv.deleteDeadline = deleteDeadline
|
lv.deleteDeadline = deleteDeadline
|
||||||
|
sv.lastValues[inputKey] = lv
|
||||||
sv.deleteDeadline = deleteDeadline
|
sv.deleteDeadline = deleteDeadline
|
||||||
}
|
}
|
||||||
sv.mu.Unlock()
|
sv.mu.Unlock()
|
||||||
|
|
Loading…
Reference in a new issue