mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmagent/common: use plain sync.Pool instead of a mix of sync.Pool with channel-based pool for PushCtx
This scheme was used for reducing memory usage when vmagent runs on a machine with big number of CPU cores and the ingestion rate isn't too big. The scheme with channel-based pool could reduce memory usage, since it minimizes the number of PushCtx structs in the pool in this case. Performance tests didn't reveal significant difference in memory usage under both low and high ingestion rate between plain sync.Pool and the current hybrid scheme, so replace the scheme with plain sync.Pool in order to simplify the code.
This commit is contained in:
parent
7531e9084a
commit
77c597738c
1 changed files with 7 additions and 15 deletions
|
@ -3,13 +3,15 @@ package common
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PushCtx is a context used for populating WriteRequest.
|
// PushCtx is a context used for populating WriteRequest.
|
||||||
type PushCtx struct {
|
type PushCtx struct {
|
||||||
|
// WriteRequest contains the WriteRequest, which must be pushed later to remote storage.
|
||||||
|
//
|
||||||
|
// The actual labels and samples for the time series are stored in Labels and Samples fields.
|
||||||
WriteRequest prompbmarshal.WriteRequest
|
WriteRequest prompbmarshal.WriteRequest
|
||||||
|
|
||||||
// Labels contains flat list of all the labels used in WriteRequest.
|
// Labels contains flat list of all the labels used in WriteRequest.
|
||||||
|
@ -33,15 +35,10 @@ func (ctx *PushCtx) Reset() {
|
||||||
//
|
//
|
||||||
// Call PutPushCtx when the ctx is no longer needed.
|
// Call PutPushCtx when the ctx is no longer needed.
|
||||||
func GetPushCtx() *PushCtx {
|
func GetPushCtx() *PushCtx {
|
||||||
select {
|
if v := pushCtxPool.Get(); v != nil {
|
||||||
case ctx := <-pushCtxPoolCh:
|
return v.(*PushCtx)
|
||||||
return ctx
|
|
||||||
default:
|
|
||||||
if v := pushCtxPool.Get(); v != nil {
|
|
||||||
return v.(*PushCtx)
|
|
||||||
}
|
|
||||||
return &PushCtx{}
|
|
||||||
}
|
}
|
||||||
|
return &PushCtx{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutPushCtx returns ctx to the pool.
|
// PutPushCtx returns ctx to the pool.
|
||||||
|
@ -49,12 +46,7 @@ func GetPushCtx() *PushCtx {
|
||||||
// ctx mustn't be used after returning to the pool.
|
// ctx mustn't be used after returning to the pool.
|
||||||
func PutPushCtx(ctx *PushCtx) {
|
func PutPushCtx(ctx *PushCtx) {
|
||||||
ctx.Reset()
|
ctx.Reset()
|
||||||
select {
|
pushCtxPool.Put(ctx)
|
||||||
case pushCtxPoolCh <- ctx:
|
|
||||||
default:
|
|
||||||
pushCtxPool.Put(ctx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pushCtxPool sync.Pool
|
var pushCtxPool sync.Pool
|
||||||
var pushCtxPoolCh = make(chan *PushCtx, cgroup.AvailableCPUs())
|
|
||||||
|
|
Loading…
Reference in a new issue