From 392ba94d1dfefcbcc2d6999d23864a82de6a06dd Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 31 Mar 2021 16:16:26 +0300 Subject: [PATCH] app/vmagent/remotewrite: reduce memory usage when `-remoteWrite.queues` is set to a big value See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1167 --- app/vmagent/remotewrite/remotewrite.go | 8 +++++++- docs/CHANGELOG.md | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/vmagent/remotewrite/remotewrite.go b/app/vmagent/remotewrite/remotewrite.go index 6c1c13b7c..7961cb560 100644 --- a/app/vmagent/remotewrite/remotewrite.go +++ b/app/vmagent/remotewrite/remotewrite.go @@ -210,7 +210,13 @@ func newRemoteWriteCtx(argIdx int, remoteWriteURL string, maxInmemoryBlocks int, c := newClient(argIdx, remoteWriteURL, sanitizedURL, fq, *queues) sf := significantFigures.GetOptionalArgOrDefault(argIdx, 0) rd := roundDigits.GetOptionalArgOrDefault(argIdx, 100) - pss := make([]*pendingSeries, *queues) + pssLen := *queues + if n := cgroup.AvailableCPUs(); pssLen > n { + // There is no sense in running more than availableCPUs concurrent pendingSeries, + // since every pendingSeries can saturate up to a single CPU. + pssLen = n + } + pss := make([]*pendingSeries, pssLen) for i := range pss { pss[i] = newPendingSeries(fq.MustWriteBlock, sf, rd) } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d50bf273d..c72b82f73 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,8 @@ # tip +* FEATURE: vmagent: reduce memory usage when `-remoteWrite.queues` is set to a big value. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1167). + # [v1.57.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.57.1)