mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/streamaggr: limit the number of concurrent flushes of aggregate metrics in order to limit memory usage
This commit is contained in:
parent
c63755c316
commit
5c4bd4f7c1
1 changed files with 10 additions and 1 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
|
@ -345,10 +346,18 @@ func (a *aggregator) runFlusher(interval time.Duration) {
|
|||
return
|
||||
case <-t.C:
|
||||
}
|
||||
|
||||
// Globally limit the concurrency for metrics' flush
|
||||
// in order to limit memory usage when big number of aggregators
|
||||
// are flushed at the same time.
|
||||
flushConcurrencyCh <- struct{}{}
|
||||
a.flush()
|
||||
<-flushConcurrencyCh
|
||||
}
|
||||
}
|
||||
|
||||
var flushConcurrencyCh = make(chan struct{}, 2*cgroup.AvailableCPUs())
|
||||
|
||||
func (a *aggregator) flush() {
|
||||
ctx := &flushCtx{
|
||||
suffix: a.suffix,
|
||||
|
@ -373,7 +382,7 @@ func (a *aggregator) flush() {
|
|||
tss = dst
|
||||
}
|
||||
|
||||
// Push the output metrics
|
||||
// Push the output metrics.
|
||||
a.pushFunc(tss)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue