lexburner commented on issue #2433: [Dubbo-random enhance] replace Random with ThreadLocalRandom URL: https://github.com/apache/incubator-dubbo/pull/2433#issuecomment-418581873 I notice another pr `https://github.com/apache/incubator-dubbo/pull/2439` try to use a `netty.ThreadLocalRandom` to replace jdk orign `ThreadLocalRandom` maybe more details need to take as consideration. 1. third-party dependency need use carefully. 2. bugs fix need to trace from upstream repository. 3. performance benchmark ``` @BenchmarkMode({Mode.AverageTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Warmup(iterations = 3, time = 5) @Measurement(iterations = 3, time = 5) @Threads(50) @Fork(1) @State(Scope.Benchmark) public class RandomBenchmark { Random random = new Random(); @Benchmark public int random() { return random.nextInt(); } @Benchmark public int threadLocalRandom() { return ThreadLocalRandom.current().nextInt(); } @Benchmark public int nettyThreadLocalRandom() { return io.netty.util.internal.ThreadLocalRandom.current().nextInt(); } public static void main(String[] args) throws RunnerException { Options opt = new OptionsBuilder() .include(RandomBenchmark.class.getSimpleName()) .build(); new Runner(opt).run(); } } ``` and below is our benchmark result under `50 concurrency` ``` Benchmark Mode Cnt Score Error Units RandomBenchmark.nettyThreadLocalRandom avgt 3 160.321 ± 83.518 ns/op RandomBenchmark.random avgt 3 3281.972 ± 2093.187 ns/op RandomBenchmark.threadLocalRandom avgt 3 91.505 ± 39.702 ns/op ``` Maybe i did sth wrong with `netty.ThreadLocalRandom`, but from the result we can know the truth > JDK 's ThreadLocalRandom looks good.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
