217 points · by pjmlp · 5y ago · 193 comments
My guess is that little time was spent optimizing the C++ and Rust codebase, and Rust performs better because the code doesn't do copies.
https://www.reddit.com/r/grpc/comments/muy8dj/grpc_bench_ope...
Small clarification (to my understanding, I'm not a Java Guru) on why Java got on top - those Java implementations use something called Direct Executor. It's super performant when there's no chance of a blocking operation. But if you are to do anything more than echo service, you might be in trouble. Other implementations probably don't suffer from the same constraint
PR and discussions here- https://github.com/LesnyRumcajs/grpc_bench/pull/91
If anything, to me it’s a clear example of why benchmarks like these are silly as they benchmark very uninteresting aspects that typically are never real world bottlenecks.
Java subs are celebrating it like they won a war. Java is a great language and will remain one of the top languages in the near future. But these silly benchmarks don't serve any purpose.
I am expecting to see this benchmark thrown around a lot from now on any language discussion. Whoever is doing these benchmarks should be more responsible and sensible.
Instead here it seems to mean something more like "is capable of deadlocking if a thread pool is exhausted" or therefore roughly equivalent to "not lock-free". Is that correct? (But then the comments about `volatile` confuse me more - can you deadlock a thread with purely `volatile` access if your platform doesn't natively support it? That seems like a large failing of the JVM.)
==> Running benchmark for java_grpc_pgc_bench... Requests/sec: 25563.46
==> Running benchmark for cpp_grpc_mt_bench... Requests/sec: 31389.24
==> Running benchmark for dotnet_grpc_bench... Requests/sec: 25376.18
==> Running benchmark for go_grpc_bench... Requests/sec: 29158.60
==> Running benchmark for rust_tonic_st_bench... Requests/sec: 28120.25
Different images for the same language (java, rust, cpp) performed with similar if not worse results
Edit: what were your latencies and memory stats like?
I executed it giving both the client and the server 4 CPUs, now I'm running it again with 180s duration and gonna update the original comment if I get to see the report or there is any significant change
With C++ and Rust you will be able to implement this in a more optimized way as you can look for approaches that avoid copies which can be the main factor of a slow implementation, specially in multi-threaded scenarios.
It does, but the numbers are not too far. It's 3.5ms for Java versus 2.3ms for C++.
Even when running a lot of requests when 99% latency becomes the average one, that's like 1 millisecond difference, way under typical user's network latency.
Latency histogram for fixed throughout (e.g. 1k RPS, 10k RPS, 50k RPS) are far more useful. You want to know if going from 1k to 10k increases latency.
These numbers are meaningless unless accompanies by specific usecases - don't just choose java or C++ just because the benchmark says its fast or the best.
High frequency trading needs that extra milli second, but a batch job or backend computation won't.
These issues can be mitigated by carefully tuning the parameters of the Java virtual machine, but in practice, for most projects, it is not an issue.
A long time ago I had to implement a real time service with Java. The best solution was to use whopping 16 megabytes of heap so that it would do a full GC multiple times per second but each of the GCs lasted less than a millisecond.
The plan is to parametrize all std collections on the allocator eventually, but that's not stable yet.
> keep objects after the request ends
Yes. Can that be made in a way compatible with per request allocators?
The whole point is that you don't. You literally pay for the memory your application requires, proportionally to the amount of memory. The difference in the resources required to run is around two orders of magnitude.
Let's put things in perspective: in some platforms such as AWS Lambda, you are charged per memory used per second.
Paying for the amount of memory you use down to the MB, is hardly something everyone does, which makes it weird that you are now the third reply that assume this runs on AWS/Lambda.
Not just that, but they were very sensitive to fluctuations.
You have exactly 0 information available and yet you make a comment like this? Is this why we have cargo-culting?
Not every solution to a problem needs to use as little memory as possible. And also not every solution can ignore memory usage. It depends, of course.
Since this thread is about throughoutput and optimizing for that, I could tell you that most times I've been put in charge for optimizing throughoutput, having low memory usage have been pretty far down the list.
The explanations could be: a) the bytecode generated by the Kotlin compiler is much worse and b) the benchmark Kotlin code is not as good or optimized as the Java one.
https://github.com/LesnyRumcajs/grpc_bench/blob/master/kotli...
https://github.com/LesnyRumcajs/grpc_bench/blob/master/java_...
Looking at the build files, different versions of the libraries appears to be used. The Java implementation is configurable but defaults to something called "direct executor".
Maybe that explains the difference.
In my case, I have a programming language interpreter implemented in Kotlin, and as an experiment I made the entire interpreter using suspending calls so that I could call asynchronous functions, and my performance tests dropped by about 20%.
Since openjdk has had to cope with lack of (user defined) value types and the garbage heavy ecosystem it has a very well optimised GC for handling heap allocations.
I wonder if the results will be different if other language benchmarks (C++ or rust) use different allocators (eg: bump allocator, per request collectors) for cheaper allocation.
pgc: ParallelGC sgc: SerialGC g1gc: G1GC she: ShenandoahGC zgc: ZGC
EDIT: Someone else noted (https://news.ycombinator.com/item?id=27085507) a discussion on Reddit where a <5ms latency was achieved in 99.9% cases, so perhaps this is indeed a subpar result.
For the single core test, we can infer an upper bound of 20-33us of server cpu time per request for most of the relevant languages for gRPC. That seems pretty good.
https://github.com/fujita/greeter-bpf
2-3x faster than GRPC-Go.
Not really anything here:
https://github.com/LesnyRumcajs/grpc_bench/tree/master/java_...
COPY java_grpc_sgc_bench /app
Directory here: https://github.com/LesnyRumcajs/grpc_bench/tree/master/java_...https://github.com/LesnyRumcajs/grpc_bench/tree/master/java_...
90k req/sec with p99 under 1ms
ghz --proto=/proto/helloworld/helloworld.proto --call=helloworld.Greeter.SayHello --insecure --concurrency="50" --connections="5" --duration "60s" --data-file 1kb.json 127.0.0.1:50051 --cpus=4
Summary:
Count: 5411979
Total: 60.00 s
Slowest: 15.24 ms
Fastest: 0.03 ms
Average: 0.34 ms
Requests/sec: 90194.36
Response time histogram:
0.026 [1] |
1.548 [997969] |∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
3.070 [1426] |
4.592 [251] |
6.114 [108] |
7.636 [87] |
9.157 [80] |
10.679 [17] |
12.201 [40] |
13.723 [11] |
15.245 [10] |
Latency distribution:
10 % in 0.12 ms
25 % in 0.19 ms
50 % in 0.29 ms
75 % in 0.42 ms
90 % in 0.58 ms
95 % in 0.72 ms
99 % in 1.04 ms
Status code distribution:
[OK] 5411959 responses
[Canceled] 3 responses
[Unavailable] 17 responses
Error distribution:
[3] rpc error: code = Canceled desc = grpc: the
client connection is closing
[17] rpc error: code = Unavailable desc = transport
is closingAlso the tool used in that benchmark ghz is also written in Go, so somehow the client is able to have high troughput and verify requests but the server can't?
Seriously, every now and then there's a story about some fintech company who use Java and use large enough heap that there's no garbage collection during stock market opening hours.
If I remember correctly the bytecode is interpreted and executed by the runtime. This means the bytecode is fully in memory as bytecode when the jvm loads .class files. The native code for the JVM interpreter and runtime execution is also present in memory.
At this point execution happens without "duplicate code" in memory.
Note: the JVM could compile the bytecode fully into native code before execution but that's an implementation detail for a specific JVM implementation.
Then we add the JIT. The JIT will notice hot paths during interpretation/execution and compile a method to native code and inject it so it calls the jit_native version instead of the bytecode_interpreted version. The JIT does not overwrite original bytecode but stores the compilation result separately.
So to come back to your statement "both bytecode and native code generated from bytecode in memory at the same time": yes, but only for the JIT-compiled hot paths.
This to me is the "power" of the JVM + JIT. Run interpreted bytecode and compile to native for the hot paths.
Why isn't teh SDK/Language major versions not mentioned in wiki page ?
Am I making mistake in reading this .... As the number of CPUs increases req/s and latency does not change, except for few java and rust readings. Network connections and IO isn't seem to scale as number of CPUs increases ?
Also, I believe the heavily editorialized title should be replaced with something that is close to the title of the original post, such as "2021-04-13 gRPC benchmark results".
Edit: it’s not even php, it’s roadrunner (a golang server) proxying for php. By default, it’s probably not configured for production.
Unfortunately I've never found a best-in-class modern RPC system for C++ that embraces integration with other libraries (for I/O, concurrency, etc)
Thrift (Apache not Facebook) and CapnProto are the only other contenders that I know of.
I know the Cloud APIs use gRPC, but only on the client side. But I'm under the impression that gRPC and Stubby (the internal RPC framework?) are completely different codebases (even if they are allegedly similar).
Results for 2 and 3 CPUs are strange too. So little scaling, what's the point...