From 3b1ecac04b5e233e6b3fe6fdcabc326749e5da65 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 30 Aug 2020 21:23:38 +0300 Subject: [PATCH] app/vmagent: apply sane limits to `-remoteWrite.queues` Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/707 --- app/vmagent/remotewrite/remotewrite.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/vmagent/remotewrite/remotewrite.go b/app/vmagent/remotewrite/remotewrite.go index effbacf548..2acb2d457a 100644 --- a/app/vmagent/remotewrite/remotewrite.go +++ b/app/vmagent/remotewrite/remotewrite.go @@ -3,6 +3,7 @@ package remotewrite import ( "flag" "fmt" + "runtime" "sync" "sync/atomic" @@ -41,6 +42,10 @@ var rwctxs []*remoteWriteCtx // Contains the current relabelConfigs. var allRelabelConfigs atomic.Value +// maxQueues limits the maximum value for `-remoteWrite.queues`. There is no sense in setting too high value, +// since it may lead to high memory usage due to big number of buffers. +var maxQueues = runtime.GOMAXPROCS(-1) * 4 + // Init initializes remotewrite. // // It must be called after flag.Parse(). @@ -48,9 +53,14 @@ var allRelabelConfigs atomic.Value // Stop must be called for graceful shutdown. func Init() { if len(*remoteWriteURLs) == 0 { - logger.Fatalf("at least one `-remoteWrite.url` must be set") + logger.Fatalf("at least one `-remoteWrite.url` command-line flag must be set") + } + if *queues > maxQueues { + *queues = maxQueues + } + if *queues <= 0 { + *queues = 1 } - if !*showRemoteWriteURL { // remoteWrite.url can contain authentication codes, so hide it at `/metrics` output. httpserver.RegisterSecretFlag("remoteWrite.url")