Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pool: Fix unsafe randomizers #643

Merged
merged 4 commits into from
Dec 5, 2024
Merged

pool: Fix unsafe randomizers #643

merged 4 commits into from
Dec 5, 2024

Conversation

cthulhu-rider
Copy link
Contributor

@cthulhu-rider cthulhu-rider commented Dec 4, 2024

we can also just mutex the panicking part, safe rand functions do the same

There is no way to access it outside the package anyway.

Signed-off-by: Leonard Lyubich <[email protected]>
Impossible to reproduce 100% consistently, but still better to have it.

Signed-off-by: Leonard Lyubich <[email protected]>
It is about to change, would be nice to track performance diff.

Signed-off-by: Leonard Lyubich <[email protected]>
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 <[email protected]>
@cthulhu-rider
Copy link
Contributor Author

i've ensured that AIO tests fail not due to these changes, so they are gonna be fixed within #644

@cthulhu-rider cthulhu-rider marked this pull request as ready for review December 4, 2024 18:32
Copy link

@AliceInHunterland AliceInHunterland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, tested with 250k parallel searchers and even a ram of 12 GB was enough for it (before it was crashing).

@cthulhu-rider cthulhu-rider merged commit 335d9fe into master Dec 5, 2024
11 of 15 checks passed
@cthulhu-rider cthulhu-rider deleted the bugfix/631 branch December 5, 2024 08:35
AliceInHunterland added a commit to nspcc-dev/neo-go that referenced this pull request Dec 12, 2024
Update to the version without pool panics https://github
.com/nspcc-dev/neofs-sdk-go/pull/643.

Signed-off-by: Ekaterina Pavlova <[email protected]>
AliceInHunterland added a commit to nspcc-dev/neo-go that referenced this pull request Dec 13, 2024
Update to the version without pool panics
nspcc-dev/neofs-sdk-go#643.

Signed-off-by: Ekaterina Pavlova <[email protected]>
AliceInHunterland added a commit to nspcc-dev/neo-go that referenced this pull request Dec 13, 2024
Update to the version without pool panics
nspcc-dev/neofs-sdk-go#643.

Signed-off-by: Ekaterina Pavlova <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants