From b05f6cf11cdc9235b27850de311f85ec2abc6f0f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 17 Jan 2020 15:43:47 +0200 Subject: [PATCH] app/vmselect: limit the default value for `-search.maxConcurrentRequests`, so it plays well on systems with more than 16 vCPUs A single heavy request can saturate all the available CPUs, so let's limit the number of concurrent requests to lower value. This will give more chances for executing insert path. --- app/vmselect/main.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/vmselect/main.go b/app/vmselect/main.go index 943b5db1a6..0a28a406aa 100644 --- a/app/vmselect/main.go +++ b/app/vmselect/main.go @@ -25,11 +25,26 @@ import ( var ( httpListenAddr = flag.String("httpListenAddr", ":8481", "Address to listen for http connections") cacheDataPath = flag.String("cacheDataPath", "", "Path to directory for cache files. Cache isn't saved if empty") - maxConcurrentRequests = flag.Int("search.maxConcurrentRequests", runtime.GOMAXPROCS(-1)*2, "The maximum number of concurrent search requests. It shouldn't exceed 2*vCPUs for better performance. See also -search.maxQueueDuration") - maxQueueDuration = flag.Duration("search.maxQueueDuration", 10*time.Second, "The maximum time the request waits for execution when -search.maxConcurrentRequests limit is reached") - storageNodes = flagutil.NewArray("storageNode", "Addresses of vmstorage nodes; usage: -storageNode=vmstorage-host1:8401 -storageNode=vmstorage-host2:8401") + maxConcurrentRequests = flag.Int("search.maxConcurrentRequests", getDefaultMaxConcurrentRequests(), "The maximum number of concurrent search requests. "+ + "It shouldn't be high, since a single request can saturate all the CPU cores. See also `-search.maxQueueDuration`") + maxQueueDuration = flag.Duration("search.maxQueueDuration", 10*time.Second, "The maximum time the request waits for execution when -search.maxConcurrentRequests limit is reached") + storageNodes = flagutil.NewArray("storageNode", "Addresses of vmstorage nodes; usage: -storageNode=vmstorage-host1:8401 -storageNode=vmstorage-host2:8401") ) +func getDefaultMaxConcurrentRequests() int { + n := runtime.GOMAXPROCS(-1) + if n <= 4 { + n *= 2 + } + if n > 16 { + // A single request can saturate all the CPU cores, so there is no sense + // in allowing higher number of concurrent requests - they will just contend + // for unavailable CPU time. + n = 16 + } + return n +} + func main() { flag.Parse() buildinfo.Init()