From 0dea4719da78f888f7f286a0db5d176af8bd52bb Mon Sep 17 00:00:00 2001 From: Alexander Rickardsson Date: Sun, 15 Sep 2019 20:12:39 +0200 Subject: [PATCH] [aggregator] make sure worker pool is at least 1 (#1881) It is possible to configure the aggregator so that the worker pool size ends up being 0. In that case, the aggregator does not perform any work, but also do not return any error messages making it very hard to understand why nothing is happening --- src/cmd/services/m3aggregator/config/aggregator.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cmd/services/m3aggregator/config/aggregator.go b/src/cmd/services/m3aggregator/config/aggregator.go index ebe73eb5d4..7e6be9901d 100644 --- a/src/cmd/services/m3aggregator/config/aggregator.go +++ b/src/cmd/services/m3aggregator/config/aggregator.go @@ -23,6 +23,7 @@ package config import ( "errors" "fmt" + "math" "net" "os" "runtime" @@ -689,7 +690,12 @@ func (c flushManagerConfiguration) NewFlushManagerOptions( opts = opts.SetMaxJitterFn(maxJitterFn) } if c.NumWorkersPerCPU != 0 { - workerPoolSize := int(float64(runtime.NumCPU()) * c.NumWorkersPerCPU) + runtimeCPU := float64(runtime.NumCPU()) + numWorkers := c.NumWorkersPerCPU * runtimeCPU + workerPoolSize := int(math.Ceil(numWorkers)) + if workerPoolSize < 1 { + workerPoolSize = 1 + } workerPool := sync.NewWorkerPool(workerPoolSize) workerPool.Init() opts = opts.SetWorkerPool(workerPool)