Go (Golang) vs Java: Performance Benchmark
Вставка
- Опубліковано 11 січ 2023
- 🔴 - To support my channel, I’d like to offer Mentorship/On-the-Job Support/Consulting - me@antonputra.com
▬▬▬▬▬ Experience & Location 💼 ▬▬▬▬▬
► I’m a Senior Software Engineer at Juniper Networks (12+ years of experience)
► Located in San Francisco Bay Area, CA (US citizen)
▬▬▬▬▬▬ Connect with me 👋 ▬▬▬▬▬▬
► LinkedIn: / anton-putra
► Twitter/X: / antonvputra
► GitHub: github.com/antonputra
► Email: me@antonputra.com
▬▬▬▬▬▬ Related videos 👨🏫 ▬▬▬▬▬▬
👉 [Playlist] Kubernetes Tutorials: • Kubernetes Tutorials
👉 [Playlist] Terraform Tutorials: • Terraform Tutorials fo...
👉 [Playlist] Network Tutorials: • Network Tutorials
👉 [Playlist] Apache Kafka Tutorials: • Apache Kafka Tutorials
👉 [Playlist] Performance Benchmarks: • Performance Benchmarks
👉 [Playlist] Database Tutorials: • Database Tutorials
▬▬▬▬▬▬▬ Source Code 📚 ▬▬▬▬▬▬▬
► GitHub: github.com/antonputra/tutoria...
#Golang #Java #DevOps - Наука та технологія
🔴 - To support my channel, I’d like to offer Mentorship/On-the-Job Support/Consulting - me@antonputra.com
nice job man, thanks a lot, I've learned a lot following your videos
Thanks Abderrazak!
I love this kind of videos, thank you.
more to come =)
Спасибо за труд!)
pojalusta =)
Great job!
Thanks Dmitri!
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..
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
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 ...
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!
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 :)
Would do the same experiment with Java 21 with virtual threads ?
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
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
Awesome video - thanks! PS - show us how to make these dashboards sometime :D
sure =)
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
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.
But why a lot of projects have microservises on Go instead of Java
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
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 =)
Very nicely presented, thank you.
thanks!
Your videos are awesome 😁
Thanks 😁
Can you please compare perfomance between Go and .NET 7?
Sure
@@AntonPutra make sure to use minimal apis and not controller based stuff
An underappreciated fact of JVM is that it does optimization for long term process. So 5:47 makes sense.
thanks for pointing out
Can you run the same test with spring3 and graalvm native image?
Sure in the future
Sir request for Rust(Actix web ) vs Rust (GRPC) in kubernetes
Sure
👎
"what does your tech stack look like?"
Anton: Yes.
🧐
Would be interesting to see Java 21 compiled to native binary with GraalVM.
actually working on it, go vs java (quarkus), which uses GraalVM
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 =)
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?
Nice test :) Slowest java framework vs one of the fastest go's...
=)
Is spring the slowest java framework? I thought it was the #1
❤Go (Golang) vs. Rust: ua-cam.com/video/QWLyIBkBrl0/v-deo.html
❤Go (Golang) vs Node JS - ua-cam.com/video/ntMKNlESCpM/v-deo.html
❤ Nginx vs Traefik: ua-cam.com/video/bgcfEW_Yh7E/v-deo.html
❤AWS Lambda Go vs. Node.js - ua-cam.com/video/kJ4gfoe7gPQ/v-deo.html
❤AWS Lambda Python vs. Node.js - ua-cam.com/video/B_OOim6XrI4/v-deo.html
Антон, 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.
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.
Кто нибудь напишите какой итог то? Кто выиграл?
ukraina =))
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?
Hey can you do Python fastapi vs nests?
sure
Java needs to fine tunning memory and spring. This will help with performance.
good to know
Whats more interesting is Golang vs Kotlin Native (Ktor server)
Thanks, I'll take a look!
Spring boot vs quarkus
Ok
Why u use spring. Go compare officefloor with fiber
😂
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 =)
You are using a bad array definition in java which is eating the stack memory
Any suggestions in the current context?
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.
Dotnet minimal apis vs java!
ok
java gets faster and faster as it learns realworld usage to optimize the compiled code. This is why the idea that Java is slower than even C is just BS. for a complex system, no compile time can really know the best optimization to use. This is where java's on the fly in time compilation shines. Because at run time it gets the code paths that is most used and has the best view of where to optimize.
Yes, it takes some cycles for java to optimize it completely. But if you have a long running program, there is simply nothing better than java. Neither for speed nor for how quickly you can build the system. Rest of the languages are only good to cover either system level programming or for short run cycle programs.
If you are running a batch application that uses 100% cpu for 10 secs and shuts down then java won't have the time to optimize, in those case just use graalvm and compile java to native code directly.
thanks for your feedback, wondering what do you think about Quarkus and compiling to native code?
try echo Instead of fiber
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.
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!
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