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