From 6360c179230b58cd9e132742286a3a092c23003d Mon Sep 17 00:00:00 2001 From: Pior Bastida Date: Thu, 11 Apr 2024 20:39:53 +0200 Subject: [PATCH] Add some jitter in the processor fetch sleep --- processor.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/processor.go b/processor.go index f1c685f8..65b850bd 100644 --- a/processor.go +++ b/processor.go @@ -179,7 +179,10 @@ func (p *processor) exec() { // Sleep to avoid slamming redis and let scheduler move tasks into queues. // Note: We are not using blocking pop operation and polling queues instead. // This adds significant load to redis. - time.Sleep(100 * time.Millisecond) + avgWaitTime := 100 + jitter := 40 + waitTime := avgWaitTime - (jitter / 2) + rand.Intn(jitter) + time.Sleep(time.Duration(waitTime) * time.Millisecond) <-p.sema // release token return case err != nil: