You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2019/11/21 07:50:51 UTC
[GitHub] [rocketmq] binglind opened a new issue #1605: [improvement] use
ThreadLocalRandom instead of Random
binglind opened a new issue #1605: [improvement] use ThreadLocalRandom instead of Random
URL: https://github.com/apache/rocketmq/issues/1605
** Performance improvement **
Random is thread safe for use by multiple threads. But if multiple threads use the same instance of Random, the same seed is shared by multiple threads. It leads to contention between multiple threads and so to performance degradation.
ThreadLocalRandom is solution to above problem. ThreadLocalRandom has a Random instance per thread and safeguards against contention.
According to jmh benchmark
Benchmark Mode Cnt Score Error Units
RandomBenchmark.random avgt 10 2616.198 ± 316.004 ns/op
RandomBenchmark.threadRandom avgt 10 3.764 ± 0.095 ns/op
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services