From f255800da35206df39961cc243dcfce5a690c516 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Tue, 13 Aug 2024 16:49:09 +0200 Subject: [PATCH] app/vminsert: returns back memory optimisation (#6794) Production workload shows that it's useful optimisation. Channel based objects pool allows to handle irregural data ingestion requests and make memory allocations more smooth. It's improves sync.Pool efficiency, since objects from sync.Pool removed after 2 GC cycles. With GOGC=30 value, GC runs significantly more often. https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6733 ### Checklist The following checks are **mandatory**: - [ ] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). --------- Signed-off-by: f41gh7 Signed-off-by: hagen1778 Co-authored-by: hagen1778 --- app/vminsert/netstorage/insert_ctx_pool.go | 24 +++++++++++++++++----- docs/CHANGELOG.md | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/vminsert/netstorage/insert_ctx_pool.go b/app/vminsert/netstorage/insert_ctx_pool.go index 6b2f4b2c71..3b1479e172 100644 --- a/app/vminsert/netstorage/insert_ctx_pool.go +++ b/app/vminsert/netstorage/insert_ctx_pool.go @@ -2,16 +2,23 @@ package netstorage import ( "sync" + + "github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup" ) // GetInsertCtx returns InsertCtx from the pool. // // Call PutInsertCtx for returning it to the pool. func GetInsertCtx() *InsertCtx { - if v := insertCtxPool.Get(); v != nil { - return v.(*InsertCtx) + select { + case ctx := <-insertCtxPoolCh: + return ctx + default: + if v := insertCtxPool.Get(); v != nil { + return v.(*InsertCtx) + } + return &InsertCtx{} } - return &InsertCtx{} } // PutInsertCtx returns ctx to the pool. @@ -19,7 +26,14 @@ func GetInsertCtx() *InsertCtx { // ctx cannot be used after the call. func PutInsertCtx(ctx *InsertCtx) { ctx.Reset() - insertCtxPool.Put(ctx) + select { + case insertCtxPoolCh <- ctx: + default: + insertCtxPool.Put(ctx) + } } -var insertCtxPool sync.Pool +var ( + insertCtxPool sync.Pool + insertCtxPoolCh = make(chan *InsertCtx, cgroup.AvailableCPUs()) +) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2dc8d47bde..07a5f2523e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -42,6 +42,8 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). * BUGFIX: [stream aggregation](https://docs.victoriametrics.com/stream-aggregation/): fix command-line flag `-remoteWrite.streamAggr.ignoreFirstIntervals` to accept multiple values and be applied per each corresponding `-remoteWrite.url`. Previously, this flag only could have been used globally for all URLs. * BUGFIX: [graphite](https://docs.victoriametrics.com/#graphite-render-api-usage): respect `-search.denyPartialResponse` cmd-line flag and `deny_partial_response` query GET param when serving requests via Graphite API. Before, partial responses were always denied. Thanks to @penguinlav for the [pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6748). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent/): account for `-usePromCompatibleNaming` cmd-line flag during when pushing data to remote storages. Thanks to @12345XXX for the [pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6776). +* BUGFIX: `vminsert` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): reduce CPU usage by limiting the number of concurrently running inserts. The issue was introduced in [this commit](https://github.com/VictoriaMetrics/VictoriaMetrics/commit/498fe1cfa523be5bfecaa372293c3cded85e75ab) starting from v1.101.0. See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6733) issue for details. + ## [v1.102.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.102.1) Released at 2024-08-01