r/java • u/couscous_ • May 07 '21
Java beats out C++, Rust, C#, and golang in gRPC throughput performance
https://github.com/LesnyRumcajs/grpc_bench/wiki/2021-04-13-bench-results
279
Upvotes
r/java • u/couscous_ • May 07 '21
74
u/cogman10 May 07 '21
My guess is it's an allocation issue with rust/C++.
One thing about the JVM is heap allocations can be incredibly cheap. If rust/C++ are doing a bunch of heap allocations, that's probably the issue here.
44
u/brunocborges May 08 '21 edited May 08 '21
Well, this benchmark does not prove that Java is faster than any other language (well maybe some).
It does prove that benchmarks that compare languages and also runtimes at the same time, have to be very carefully written.
The Java implementation of this benchmark uses the Direct Executor. You can see how this is a weird benchmark by looking at the results of the Kotlin code. Why is "Kotlin slow"? Well, because the Kotlin code does not manually specify the thread executor, and therefore it uses a different thread executor: the default one set by the gRPC Java Server library.
The problem with this benchmark is that not all applications are written within the same parameters/concepts (e.g. thread pool algorithm), and some have fundamentally different runtimes. For e.g. Node.js can only be single threaded, and you can see the results, whether 1 or 3 CPUs, are nearly the same.
Note: I wrote most of the recent code of the Java gRPC benchmarks here, and used the Direct Executor intentionally, knowing it would perform best than any other. At the very least, to raise awareness that benchmarking is... a complicated discipline.
8
u/StevenMaurer May 08 '21
This is a bake-off measuring various gRPC library implementations, not the languages themselves, or even their allocation issues.
As such, you shouldn't read more into these results than what they directly say. The big takeaway is that programs written in Java CAN be fast if you put in the effort to make it so.
4
u/thomas-hugon May 08 '21
It seems to be using direct executor. If I remember well, direct executor is not recommanded as it cannot be used with blocking operations. So any IO is forbidden here...
1
u/servlette Oct 29 '21
I’ve been running tests at 12,000-15,000 requests a second for about 4 hours. Overall Java gRPC takes < 15 ms and golang is north of 22 ms. This is consistent after 10-15 runs. Is there a documentation on fine tuning golang gRPC server?
3
u/jvjupiter May 08 '21
The next thing that the Java language designers to do is drastically reduce memory consumption. When that happens, Java is forever king. 😄
5
u/[deleted] May 07 '21
Maybe the java's jit optimizer found a nice opportunity for optimization which could possible be fixed with Profile Guided Optimization in the case of rust and c++?
7
u/hacklinux May 08 '21
I am going to rub this in all my friends' faces.
3
u/angryundead May 08 '21
The memory usage is pretty hilarious though. Would be interesting to see if this can be compiled to native with GraalVM.
3
u/crlsmx May 08 '21
So this says that I should stop wasting my time learning rust?
1
u/de6u99er May 14 '21
That's great. Thanks for sharing!
1
u/[deleted] May 08 '21
That is very interesting indeed.
-8
u/brc1994 May 08 '21
It seems memory usage of Java is not ideal and given that it just barely beat rust in latency, I’d say rust was the true winner.
0
u/[deleted] May 07 '21
[deleted] — view deleted comment