From c22da2f917bda55f21c55a8cd1249cb0f83479f9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 20 Apr 2024 21:37:00 +0200 Subject: [PATCH] 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 77c597738cb1db719a3f458cd660b63e89412f3e --- app/vmagent/influx/request_handler.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/app/vmagent/influx/request_handler.go b/app/vmagent/influx/request_handler.go index df1645677..b8255e86f 100644 --- a/app/vmagent/influx/request_handler.go +++ b/app/vmagent/influx/request_handler.go @@ -10,7 +10,6 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/remotewrite" "github.com/VictoriaMetrics/VictoriaMetrics/lib/auth" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" - "github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup" "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel" parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common" @@ -160,25 +159,15 @@ func (ctx *pushCtx) reset() { } func getPushCtx() *pushCtx { - select { - case ctx := <-pushCtxPoolCh: - return ctx - default: - if v := pushCtxPool.Get(); v != nil { - return v.(*pushCtx) - } - return &pushCtx{} + if v := pushCtxPool.Get(); v != nil { + return v.(*pushCtx) } + return &pushCtx{} } func putPushCtx(ctx *pushCtx) { ctx.reset() - select { - case pushCtxPoolCh <- ctx: - default: - pushCtxPool.Put(ctx) - } + pushCtxPool.Put(ctx) } var pushCtxPool sync.Pool -var pushCtxPoolCh = make(chan *pushCtx, cgroup.AvailableCPUs())