-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pool: Use concurrency-safe random number generator in sampler
Previously, pool used `rand.NewSource` which is documented as 'not safe for concurrent use by multiple goroutines'. Since pool is generally accessed from multiple goroutines, it could finish with panic thrown by the mentioned component. Now pool uses safe random generators from the same `math/rand` package. Previous approach is kept for some tests that do not need multi-threading. Benchmark runs show that execution speed has obviously dropped due to sync costs, but it is negligible: ``` goos: linux goarch: amd64 pkg: github.com/nspcc-dev/neofs-sdk-go/pool cpu: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz │ sec/op │ Sampler-8 37.93n ± 13% │ B/op │ Sampler-8 0.000 ± 0% │ allocs/op │ Sampler-8 0.000 ± 0% ``` Fixes #631. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
- Loading branch information
1 parent
9eaf6fb
commit fd1e188
Showing
3 changed files
with
23 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters