forked from TrueCloudLab/frostfs-node
[#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>
This commit is contained in:
parent
f9d9f33461
commit
abfcc7498c
1 changed files with 5 additions and 0 deletions
|
@ -3,6 +3,7 @@ package policer
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"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/local_object_storage/engine"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/util/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
type jobQueue struct {
|
type jobQueue struct {
|
||||||
|
@ -19,6 +20,10 @@ func (q *jobQueue) Select(limit int) ([]*object.Address, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rand.New().Shuffle(len(res), func(i, j int) {
|
||||||
|
res[i], res[j] = res[j], res[i]
|
||||||
|
})
|
||||||
|
|
||||||
if len(res) < limit {
|
if len(res) < limit {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue