app/vmagent/influx: replace hybrid channel-based pool + sync.Pool with plain sync.Pool for pushCtx

Data ingestion benchmark doesn't show memory usage difference between two approaches,
so let's use simpler approach in order to improve code readability and maintainability.

This is a follow-up for 77c597738c
This commit is contained in:
Aliaksandr Valialkin 2024-04-20 21:37:00 +02:00
parent 77c597738c
commit c22da2f917
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -10,7 +10,6 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/remotewrite" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/remotewrite"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/auth" "github.com/VictoriaMetrics/VictoriaMetrics/lib/auth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"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"
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common" parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
@ -160,25 +159,15 @@ func (ctx *pushCtx) reset() {
} }
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{}
} }
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())