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
Go random number generation is single threaded #1469
Comments
I took a look into this and made a benchmark with a golang xorshift library I found on github: https://github.com/lazybeaver/xorshift#description Here is the benchmark I made: http://pastebin.com/wEMKSqPf To run:
Findings (with fluff edited out):
Looks to me like you are right about the slowdown on I can go ahead and update the tests after some peeps have had a chance to look at this. |
I wrote https://github.com/dgryski/trifles/blob/master/fastrand/fastrand.go that includes Intn to avoid modulo bias on bounded ranges. The slowdown will be larger under concurrent code due to lock contention, so it's not just the speed of the RNG. |
Did you measured? |
I have not benchmarked this particular case, but have seen numerous times in the past where access to a single-threaded rand instance has caused performance degradation due to lock contention. I'm fine to ignore this issue until a blocking profile shows otherwise. |
RNG is used only in Fortune test. |
Looking at https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Go/go/src/hello/hello.go it seems |
I'm sorry, I was wrong. |
Locks in
|
Additionally, there is |
As I said, I'm fine to ignore this until it shows up in a profile. |
It might be interesting to profile with the new lock-contention profile in 1.8: https://rakyll.org/mutexprofile/ |
Similar to the java issue #1152 , all calls to rand.Intn() are behind a single murex in go to prevent concurrent access to the RNG. These calls should be updated to use an xorshift RNG seeded with the current time in nanoseconds.
https://github.com/TechEmpower/FrameworkBenchmarks/search?q=rand.Intn&type=Code&utf8=✓
The text was updated successfully, but these errors were encountered: