[#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 <leonard@nspcc.ru>
remotes/fyrchik/meta-pebble
Leonard Lyubich 2021-08-24 13:44:34 +03:00 committed by Alex Vanin
parent f9d9f33461
commit abfcc7498c
1 changed files with 5 additions and 0 deletions

View File

@ -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
}