From eb47ad4b69095f8adeb40ef076418f4056c365fa Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin <valyala@victoriametrics.com> Date: Thu, 6 Jul 2023 10:02:47 -0700 Subject: [PATCH] app/vmselect/netstorage: remove runtime.Gosched() call from unpackWorker() This should improve scalability of unpackWorker() on systems with many CPU cores. This is a follow-up for a2ecf4fa4afadd5a460dc8a050aafff9a33e60f6 and 16f3b279a208a0693c6d6d46ba33c1ca47c88dc0 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3966 --- app/vmselect/netstorage/netstorage.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index 1a90d74e04..5c5e654dfb 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -9,7 +9,6 @@ import ( "net" "net/http" "os" - "runtime" "sort" "strings" "sync" @@ -410,8 +409,11 @@ func unpackWorker(workChs []chan *unpackWork, workerID uint) { idx := (i + workerID) % uint(len(workChs)) ch := workChs[idx] for len(ch) > 0 { - // Give a chance other goroutines to perform their work - runtime.Gosched() + // Do not call runtime.Gosched() here in order to give a chance + // the real owner of the work to complete it, since it consumes additional CPU + // and slows down the code on systems with big number of CPU cores. + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3966#issuecomment-1483208419 + // It is expected that every channel in the workChs is already closed, // so the next line should return immediately. upw, ok := <-ch