[improvement] use ThreadLocalRandom instead of Random
- Dominant language
- Java
- Stars
- 22.6k
- Forks
- 12k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 26
Description
** 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,10 threads,AverageTime
RandomBenchmark.random: 2616.198 ns/op
RandomBenchmark.threadRandom: 3.764 ns/op
Contributor guide
Research direction
No source files, tests, or entry points are named in the issue. Search the RocketMQ Java code for shared uses of Random, then identify which uses are suitable for ThreadLocalRandom and verify the reported contention improvement with the referenced benchmark or relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100