From abfcc7498c9ddcaacc05e2a6f16e2a2b9828d4d0 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 24 Aug 2021 13:44:34 +0300 Subject: [PATCH] [#715] services/policer: Select pseudo-random list of objects to check In previous implementation of Policer's job queue the same list of objects for processing was selected at each iteration. This was caused by consistent return of `engine.List` function. Use `rand.Shuffle` function to compose pseudo-random list of all objects in order to approximately evenly distribute objects to work. Signed-off-by: Leonard Lyubich --- pkg/services/policer/queue.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/services/policer/queue.go b/pkg/services/policer/queue.go index 88afaf7b..ac7c5336 100644 --- a/pkg/services/policer/queue.go +++ b/pkg/services/policer/queue.go @@ -3,6 +3,7 @@ package policer import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" + "github.com/nspcc-dev/neofs-node/pkg/util/rand" ) type jobQueue struct { @@ -19,6 +20,10 @@ func (q *jobQueue) Select(limit int) ([]*object.Address, error) { return nil, err } + rand.New().Shuffle(len(res), func(i, j int) { + res[i], res[j] = res[j], res[i] + }) + if len(res) < limit { return res, nil }