🔴 - To support my channel, I’d like to offer Mentorship/On-the-Job Support/Consulting - me@antonputra.com 👉 [NEW] Java (Quarkus) vs. Go (Golang): Performance Benchmark in Kubernetes - ruclips.net/video/PL0c-SvjSVg/видео.html
Anton, you forgot to warm up the Java application before running your tests. Java has a runtime compiler (JIT) which compiles the byte code to binary code. This is why Java applications are slow to process the initial requests. As you saw in your test when the Java application is warmed up then performance is fully on par with Go. Sometimes even faster.
@@ylioo Yes, if testing something else than Spring. Say using Java 19 with virtual threads enabled, together with the Javalin framework which uses the Jetty server, on a fully warmed up application, then the results would've been quite different.
@@petersburgh78 It's mainly the JVM + JIT compiler which consumes most of the memory. You have to run a native GraalVM image of the application (using any framework) to have similar memory usage as the Go application. Personally I prefer the Javalin framework for it's simplicity and performance.
You can't count on JIT to speed up execution, it has its own rules to figure out what can and cannot be optimized, it needs sometimes thousands of executions, and most of the time, the optimization are not the best, if you want to take advantage of JIT, you first need to learn how it works, and than generate beforehand java code that can really by optimized by JIT, at the end of the day, your Java code will resemble a C code ... JIT working and optimization are not that trivial ...
This benchmark is quite funny. It's always the new developers getting misled by language speed, which is the first "preoptimization is the root of all evil" they have done in their life. What they are rating is only the compiler or interpreter/jitter. And even they rated it wrong. Most mature and established have their own way to achieve speed at least comparable to other language. After all, after compilations, it all boils down to the "same" machine language anyway. The real bottleneck is the language structure formed from dedicated contracted language features, for example, the garbage collector of Java and Golang. These kinds of language features are the ones "hindering" language execution speed. But they exists for a reason, and other programming languages exists for a reason. Back to your application, if it's mainline JDK 19, im pretty sure your Spring is not getting hot (in term of getting jitted). You can tune this with compiler arguments, but the default Hotspot for C2 is 20000. The execution speed diff between an interpreter and C2 Jitted is at worst 5 times, but normally 20 up to 100 times faster. Also, this is a bit peculiar to Spring. Spring business logic methods doesn't get jitted before first request because Spring itself doesnt make the code hot by any means. Which is why at the start Spring reponse time is so terrible, becase it was ran in interpreted (or at most C1) mode. Another point, Golang use goroutines, or fibers whatever you call them to handle requests. It is a sophisicated Go-specific concurrency structure designed for scalability. It is much more scalable than thread per request (what you used, spring-mvc built on servlet framework) model. A temporary fix is virtual threads, but virtual threads have its own problems. Currently only the rx programming style most reliably helps you.
@@gandalfthegrey2777AFAIK it's not Spring in particular, it's the JVM behavior: if JVM "sees" it can grab more memory without calling GC, it takes it. There are a ton of optimization behaviors tied to memory hogging, which is why in pretty much all benchmarks Java is always using more memory at first glance. The thing is benchmarks rarely give long-term performance stats so it always seems like JVM ate all the memory and CPU for nothing 😅
@@gandalfthegrey2777 yes, but at the same time no, because it's not that simple. JVM uses memory for caching. Basically, the strategy for most languages (and even GraalVM) is "If I don't need the data, I free the memory" while JVM is more like "I won't be bothered freeing memory until I really need to"
Nice, actually I wasn’t surprised by second test, rather by the first one, from my (note a broad but still) experience java pretty comparable to go, in raw computation it’ usually faster (a bit), when it comes to something more complex, too many things varies, often times it can be slower though. It greatly depends on the framework. But I like how you orchestrate it with Prometheus and Grafana monitoring. Precious.
which solution did u use for the spring? rx or old plain thread per request? I think you will get different results with rx in spring. also spring is not the fastest framework as u know. comparing plain golang with a monstrous framework is not fare. it will be better at least to compare with smth like ktor, vert.x or at least micronaut or quarkus.
Hi Anton. Great vídeo!. I've been searching for a good comparison between these 2 for a while. Could you give me some advise based on your experience?. I'm a java dev and I consider to switch to another language. Java is still relevant but a lot of Jobs out there are mantaining legacy code on old big projects. I want to focused on backend so I'm between go, C#(last versions are great), nodejs (TS). Which of these do you recommend me based on community, salaries, libraries, tools, writing code experience, etc?.
Based on my experience, there are lots of go code nowadays. You can't go wrong with it in the near future. Especially with migration to cloud environments, it has become even more popular.
Thanks, I've been thinking about making a live Grafana with all results accessible online. Do you think it would be helpful? (This includes all benchmarks, not just the ones from this video.)
When you are comparing memory usage of containers of java and golang., java has jvm running in the container along with your application while go lang does not have such virtual env
So you are comparing apples with oranges. I see that you use Fibers from Go with Spring Boot Web, which doesn't use the same programming model(Spring Boot Web uses thread per request model) If you are switching to Spring Web Flux and Async Client for Mongo and S3 be sure that the difference will not be the same. It might be the case that Go is still faster, but the differences will not be the same as in this video. BTW congrats on this nice video.
I'm not sure this matters. Spring's marketing advertises it as being fast out of the box, and handling a few hundred requests a second should be simple for any web server, non-blocking or blocking. That being said, we know that there are Spring applications out there that do handle this kind of load, so I'd be wondering if there was something else going on in the test.
Good video. I'd spend a little more time going over the numbers and explaining how the code works, though - that's a lot of info packed into 7 minutes.
@@jonnyd6087 It's not the fastest, but one of the most robust covering almost all aspects of a modern stack. People don't use Spring for speed. However things are changing with virtual threads for scalability and AOT compilation if startup is important.
Hey Anton, awesome banchmark and showcase. But I must ask, what's that vs code theme? I generally use other code editors, but that theme looks good enough to start using vs code again :D
I wonder how Rust would fit in this picture. Judging by your Gin (Go) vs Rocket (Rust) test, it would beat both, I guess, but it is still interesting by what margin. Would it be possible to do some kind of cumulative test to wrap up frameworks you've tested so far (say 5 or 10 frameworks)?
Always thought if one tries to compare languages and runtimes performance - need to minimise number of moving parts in the test, not maximise them. I'd say practical conclusions from this test are very limited. But I like your automation setup.
@@AntonPutra the end was kind of a shock to me since go bad been doing so well the whole time. What do you think could have been the cause of that spike? Would you consider doing the same test with go gin?
To be honest, I don't find any value in this benchmark. You just took the slowest framework in java and didn't even try to warm up and tune the JVM to run it properly. Why don't you take Quarkus, Micronaut or just a simple app on top of Vert.x? What about GraalVM Native Image? Writing high efficient code means that you go deeper into the features of specific language and tune them as much as possible to fit into your requirenments. If you wanted to show us how to gather logs and build a dashboard based on it, then please name the video properly.
For every Image you create format object but you can create it only one time. Move this out of method to static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); You can set it once in static block as well sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
@@AntonPutra , it means that we only use 0.2 CPU cores or 20% of a single core. Not even a core. The situation will be completely changed when running the Go code on a multicore machine, because the superpower (or "killer feature" if you like) of Golang is its ability to harness the full potential of multiple cores in a machine.
For DevOps, learn Go because most infrastructure plugins, such as Terraform providers and Kubernetes operators, are written in Go. So if you are a DevOps engineer, you should definitely learn Go, and performance has nothing to do with it.
There's an article on it. Go was superior based on the be article. Many java heads here are saying that java apps need to "warm up", be "tuned", set to 'thread per request', and use custom VMS And other things in order to be accurately compared to golang. All in all I'd say this is inconclusive. Take the most expertly written golang server vs the most expertly written java server and then I'd like to see THAT. Overall for people who aren't extraordinarily versed in the intricacies of java it does seem like go provides easier to achieve performance.
🔴 - To support my channel, I’d like to offer Mentorship/On-the-Job Support/Consulting - me@antonputra.com
👉 [NEW] Java (Quarkus) vs. Go (Golang): Performance Benchmark in Kubernetes - ruclips.net/video/PL0c-SvjSVg/видео.html
Anton, you forgot to warm up the Java application before running your tests. Java has a runtime compiler (JIT) which compiles the byte code to binary code. This is why Java applications are slow to process the initial requests. As you saw in your test when the Java application is warmed up then performance is fully on par with Go. Sometimes even faster.
@@ylioo Yes, if testing something else than Spring. Say using Java 19 with virtual threads enabled, together with the Javalin framework which uses the Jetty server, on a fully warmed up application, then the results would've been quite different.
Thanks pompiuses! I appreciate your feedback!
Also, consider benchmarking with other Java frameworks, such as Quarkus which consume less memory than Spring Boot.
@@petersburgh78 It's mainly the JVM + JIT compiler which consumes most of the memory. You have to run a native GraalVM image of the application (using any framework) to have similar memory usage as the Go application. Personally I prefer the Javalin framework for it's simplicity and performance.
You can't count on JIT to speed up execution, it has its own rules to figure out what can and cannot be optimized, it needs sometimes thousands of executions, and most of the time, the optimization are not the best, if you want to take advantage of JIT, you first need to learn how it works, and than generate beforehand java code that can really by optimized by JIT, at the end of the day, your Java code will resemble a C code ... JIT working and optimization are not that trivial ...
Would do the same experiment with Java 21 with virtual threads ?
lets settle java vs dotnet :D
sure =)
@@AntonPutra let me know if you need any help with dotnet setup
@@biplovkc4100 why not, let’s come up with test scenario and then can you create PR?
@@AntonPutra sounds good. Ping me with the scenario you have in mind and let's start
It would be great to watch this comparison!
Спасибо за труд!)
pojalusta =)
nice job man, thanks a lot, I've learned a lot following your videos
Thanks Abderrazak!
An underappreciated fact of JVM is that it does optimization for long term process. So 5:47 makes sense.
thanks for pointing out
I love this kind of videos, thank you.
more to come =)
Would be interesting to see Java 21 compiled to native binary with GraalVM.
actually working on it, go vs java (quarkus), which uses GraalVM
This benchmark is quite funny. It's always the new developers getting misled by language speed, which is the first "preoptimization is the root of all evil" they have done in their life.
What they are rating is only the compiler or interpreter/jitter. And even they rated it wrong. Most mature and established have their own way to achieve speed at least comparable to other language. After all, after compilations, it all boils down to the "same" machine language anyway. The real bottleneck is the language structure formed from dedicated contracted language features, for example, the garbage collector of Java and Golang. These kinds of language features are the ones "hindering" language execution speed. But they exists for a reason, and other programming languages exists for a reason.
Back to your application, if it's mainline JDK 19, im pretty sure your Spring is not getting hot (in term of getting jitted). You can tune this with compiler arguments, but the default Hotspot for C2 is 20000. The execution speed diff between an interpreter and C2 Jitted is at worst 5 times, but normally 20 up to 100 times faster.
Also, this is a bit peculiar to Spring. Spring business logic methods doesn't get jitted before first request because Spring itself doesnt make the code hot by any means. Which is why at the start Spring reponse time is so terrible, becase it was ran in interpreted (or at most C1) mode.
Another point, Golang use goroutines, or fibers whatever you call them to handle requests. It is a sophisicated Go-specific concurrency structure designed for scalability. It is much more scalable than thread per request (what you used, spring-mvc built on servlet framework) model. A temporary fix is virtual threads, but virtual threads have its own problems. Currently only the rx programming style most reliably helps you.
It's pretty clear he isn't so knowledgeable about how to run java at it's full Performa and the jit was not even taken into consideration
is spring that resource heavy? Taking 50% memory where go only taking 6%?
@@gandalfthegrey2777AFAIK it's not Spring in particular, it's the JVM behavior: if JVM "sees" it can grab more memory without calling GC, it takes it. There are a ton of optimization behaviors tied to memory hogging, which is why in pretty much all benchmarks Java is always using more memory at first glance. The thing is benchmarks rarely give long-term performance stats so it always seems like JVM ate all the memory and CPU for nothing 😅
@@Toisen so it holds it with itself and can allocate later?
So if Go were to expand upto 40%, Java would still be at 50% for same load?
@@gandalfthegrey2777 yes, but at the same time no, because it's not that simple. JVM uses memory for caching. Basically, the strategy for most languages (and even GraalVM) is "If I don't need the data, I free the memory" while JVM is more like "I won't be bothered freeing memory until I really need to"
Nice, actually I wasn’t surprised by second test, rather by the first one, from my (note a broad but still) experience java pretty comparable to go, in raw computation it’ usually faster (a bit), when it comes to something more complex, too many things varies, often times it can be slower though. It greatly depends on the framework.
But I like how you orchestrate it with Prometheus and Grafana monitoring. Precious.
Yeah, fiber is pretty fast by itself..
But why a lot of projects have microservises on Go instead of Java
which solution did u use for the spring? rx or old plain thread per request? I think you will get different results with rx in spring. also spring is not the fastest framework as u know. comparing plain golang with a monstrous framework is not fare. it will be better at least to compare with smth like ktor, vert.x or at least micronaut or quarkus.
or maybe just compare go with pure java. no frameworks, nothing. it will also be interesting to see the multithreading in both. anyways, good video.
Yeah, good point.
Can you please compare perfomance between Go and .NET 7?
Sure
@@AntonPutra make sure to use minimal apis and not controller based stuff
Hi anton, I wanted to ask. Do you like blogs? if so what are your favorite blogs?
same with books
I really enjoy your videos, thanks for your work
Right now my favorite is rust book =)
Hi Anton. Great vídeo!. I've been searching for a good comparison between these 2 for a while. Could you give me some advise based on your experience?. I'm a java dev and I consider to switch to another language. Java is still relevant but a lot of Jobs out there are mantaining legacy code on old big projects. I want to focused on backend so I'm between go, C#(last versions are great), nodejs (TS). Which of these do you recommend me based on community, salaries, libraries, tools, writing code experience, etc?.
Based on my experience, there are lots of go code nowadays. You can't go wrong with it in the near future. Especially with migration to cloud environments, it has become even more popular.
don't worry. in 3-4 years you also will see a lot of old, legacy golang code :)
❤Go (Golang) vs. Rust: ruclips.net/video/QWLyIBkBrl0/видео.html
❤Go (Golang) vs Node JS - ruclips.net/video/ntMKNlESCpM/видео.html
❤ Nginx vs Traefik: ruclips.net/video/bgcfEW_Yh7E/видео.html
❤AWS Lambda Go vs. Node.js - ruclips.net/video/kJ4gfoe7gPQ/видео.html
❤AWS Lambda Python vs. Node.js - ruclips.net/video/B_OOim6XrI4/видео.html
Sir request for Rust(Actix web ) vs Rust (GRPC) in kubernetes
Sure
👎
Thanks for sharing. You've put a lot effort into it. Did you share somewhere the results like the report you mentioned in the video?
Thanks, I've been thinking about making a live Grafana with all results accessible online. Do you think it would be helpful? (This includes all benchmarks, not just the ones from this video.)
@@AntonPutra I think it would not be necessary to make a live Grafana board. Having some screenshots from your results would be already sufficient.
@@omerkarahan2482 got it
"what does your tech stack look like?"
Anton: Yes.
🧐
When you are comparing memory usage of containers of java and golang., java has jvm running in the container along with your application while go lang does not have such virtual env
true
When GraalVM becomes mainstream, we don't need the JVM to run our Java apps in the cloud. That would level the playing field.
So you are comparing apples with oranges.
I see that you use Fibers from Go with Spring Boot Web, which doesn't use the same programming model(Spring Boot Web uses thread per request model)
If you are switching to Spring Web Flux and Async Client for Mongo and S3 be sure that the difference will not be the same.
It might be the case that Go is still faster, but the differences will not be the same as in this video.
BTW congrats on this nice video.
Yes the JVM is quite competitive
Thanks Robert, I'll keep it in mind
Or use Java 19 which has virtual threads and so has a similar performance boost as switching to webflux.
@@NicolasdeJong Virtual Thread is still in preview
I'm not sure this matters. Spring's marketing advertises it as being fast out of the box, and handling a few hundred requests a second should be simple for any web server, non-blocking or blocking. That being said, we know that there are Spring applications out there that do handle this kind of load, so I'd be wondering if there was something else going on in the test.
Great job!
Thanks Dmitri!
In the second test, the go code performs badly because you didn't release the file descriptors associated with the s3 image download connections
Yeap, thanks for feedback. I'll fix it for the new tests..
Interesting! What do you mean by release?
@@AntonPutra how about the new tests ? can you send me the link?
Good video. I'd spend a little more time going over the numbers and explaining how the code works, though - that's a lot of info packed into 7 minutes.
Thanks! more to come =)
Java needs to fine tunning memory and spring. This will help with performance.
good to know
Very nicely presented, thank you.
thanks!
Nice test :) Slowest java framework vs one of the fastest go's...
=)
Is spring the slowest java framework? I thought it was the #1
@@jonnyd6087 It's not the fastest, but one of the most robust covering almost all aspects of a modern stack. People don't use Spring for speed. However things are changing with virtual threads for scalability and AOT compilation if startup is important.
Your videos are awesome 😁
Thanks 😁
Hey Anton, awesome banchmark and showcase. But I must ask, what's that vs code theme? I generally use other code editors, but that theme looks good enough to start using vs code again :D
Its called Nord Theme
Thanks, it's Nord Theme
I wonder how Rust would fit in this picture. Judging by your Gin (Go) vs Rocket (Rust) test, it would beat both, I guess, but it is still interesting by what margin.
Would it be possible to do some kind of cumulative test to wrap up frameworks you've tested so far (say 5 or 10 frameworks)?
At some point in the future
@@alexandrep4913 rust is so ridiculously complicated IMO
Always thought if one tries to compare languages and runtimes performance - need to minimise number of moving parts in the test, not maximise them. I'd say practical conclusions from this test are very limited. But I like your automation setup.
Thanks! It's more about ecosystem
@@AntonPutra the end was kind of a shock to me since go bad been doing so well the whole time. What do you think could have been the cause of that spike? Would you consider doing the same test with go gin?
Awesome video - thanks! PS - show us how to make these dashboards sometime :D
sure =)
Кто нибудь напишите какой итог то? Кто выиграл?
ukraina =))
@@AntonPutra вы из Украины?
This is not language, but frameworks (especially Go one he choose is not needed and slow as hell).
it's always framework :)
Hey can you do Python fastapi vs nests?
sure
To be honest, I don't find any value in this benchmark.
You just took the slowest framework in java and didn't even try to warm up and tune the JVM to run it properly.
Why don't you take Quarkus, Micronaut or just a simple app on top of Vert.x? What about GraalVM Native Image?
Writing high efficient code means that you go deeper into the features of specific language and tune them as much as possible to fit into your requirenments.
If you wanted to show us how to gather logs and build a dashboard based on it, then please name the video properly.
I appreciate your feedback! Quarkus is coming soon.
You are using a bad array definition in java which is eating the stack memory
Any suggestions in the current context?
For every Image you create format object but you can create it only one time.
Move this out of method to static
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
You can set it once in static block as well sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
thanks
Why u use spring. Go compare officefloor with fiber
😂
Антон, what is the amount of CPUs in this test?
It's a bit tricky, but k8s limit it to 200m - github.com/antonputra/tutorials/blob/main/lessons/145/go-app/deploy/deployment.yaml#L36-L41
@@AntonPutra , it means that we only use 0.2 CPU cores or 20% of a single core. Not even a core. The situation will be completely changed when running the Go code on a multicore machine, because the superpower (or "killer feature" if you like) of Golang is its ability to harness the full potential of multiple cores in a machine.
Can you run the same test with spring3 and graalvm native image?
Sure in the future
Honestly Fiber is not that common cause of its performance Gin would be better
Well, based on the feedback on my previous video (go vs rust), no one likes gin anymore =)
Hey guy, a serious problem, if you're still using Lastpass, get off it forever. Move to anywhere else, idc, stop using Lastpass
Thanks, about to create tutorial how to host your own password manager!
Whats more interesting is Golang vs Kotlin Native (Ktor server)
Thanks, I'll take a look!
I am extremely confused by the end of the video, which of both is better for DevOps?
For DevOps, learn Go because most infrastructure plugins, such as Terraform providers and Kubernetes operators, are written in Go. So if you are a DevOps engineer, you should definitely learn Go, and performance has nothing to do with it.
@@AntonPutra Thanks
Next time make java native vs golang
What is java native?
@@AntonPutra likely GraalVM built native images as I mentioned in my comment
I am also curious about the results.
There's an article on it. Go was superior based on the be article. Many java heads here are saying that java apps need to "warm up", be "tuned", set to 'thread per request', and use custom VMS And other things in order to be accurately compared to golang. All in all I'd say this is inconclusive. Take the most expertly written golang server vs the most expertly written java server and then I'd like to see THAT. Overall for people who aren't extraordinarily versed in the intricacies of java it does seem like go provides easier to achieve performance.
Spring boot vs quarkus
Ok
Dotnet minimal apis vs java!
ok
try echo Instead of fiber