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
  • Наука та технологія

КОМЕНТАРІ • 138

  • @AntonPutra
    @AntonPutra  Рік тому +1

    🔴 - To support my channel, I’d like to offer Mentorship/On-the-Job Support/Consulting - me@antonputra.com

  • @awstherapy
    @awstherapy Рік тому +5

    nice job man, thanks a lot, I've learned a lot following your videos

  • @primux2007
    @primux2007 Рік тому +4

    I love this kind of videos, thank you.

  • @n1kk0n
    @n1kk0n Рік тому +7

    Спасибо за труд!)

  • @dmitrikonnov922
    @dmitrikonnov922 Рік тому +1

    Great job!

  • @kamurashev
    @kamurashev Рік тому +23

    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.

    • @AntonPutra
      @AntonPutra  Рік тому +4

      Yeah, fiber is pretty fast by itself..

  • @omerkarahan2482
    @omerkarahan2482 10 місяців тому +2

    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?

    • @AntonPutra
      @AntonPutra  10 місяців тому +1

      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.)

    • @omerkarahan2482
      @omerkarahan2482 10 місяців тому

      @@AntonPutra I think it would not be necessary to make a live Grafana board. Having some screenshots from your results would be already sufficient.

    • @AntonPutra
      @AntonPutra  10 місяців тому +1

      @@omerkarahan2482 got it

  • @pompiuses
    @pompiuses Рік тому +34

    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.

    • @pompiuses
      @pompiuses Рік тому +4

      @@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.

    • @AntonPutra
      @AntonPutra  Рік тому +1

      Thanks pompiuses! I appreciate your feedback!

    • @petersburgh78
      @petersburgh78 Рік тому +2

      Also, consider benchmarking with other Java frameworks, such as Quarkus which consume less memory than Spring Boot.

    • @pompiuses
      @pompiuses Рік тому +1

      @@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.

    • @RicardoSilvaTripcall
      @RicardoSilvaTripcall 11 місяців тому

      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 ...

  • @biplovkc4100
    @biplovkc4100 Рік тому +59

    lets settle java vs dotnet :D

    • @AntonPutra
      @AntonPutra  Рік тому +5

      sure =)

    • @biplovkc4100
      @biplovkc4100 Рік тому

      @@AntonPutra let me know if you need any help with dotnet setup

    • @AntonPutra
      @AntonPutra  Рік тому

      @@biplovkc4100 why not, let’s come up with test scenario and then can you create PR?

    • @biplovkc4100
      @biplovkc4100 Рік тому

      @@AntonPutra sounds good. Ping me with the scenario you have in mind and let's start

    • @TheSiddhaartha
      @TheSiddhaartha Рік тому

      It would be great to watch this comparison!

  • @matstark776
    @matstark776 Рік тому +3

    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?.

    • @AntonPutra
      @AntonPutra  Рік тому +2

      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.

    • @jackdanyal4329
      @jackdanyal4329 Рік тому +3

      don't worry. in 3-4 years you also will see a lot of old, legacy golang code :)

  • @gayanperera7273
    @gayanperera7273 3 місяці тому +2

    Would do the same experiment with Java 21 with virtual threads ?

  • @Taurdil
    @Taurdil Рік тому +5

    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)?

    • @AntonPutra
      @AntonPutra  Рік тому

      At some point in the future

    • @jonnyd6087
      @jonnyd6087 Рік тому +7

      ​@@alexandrep4913 rust is so ridiculously complicated IMO

  • @helloworld7796
    @helloworld7796 Рік тому +1

    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

  • @mfc1190
    @mfc1190 Рік тому +1

    Awesome video - thanks! PS - show us how to make these dashboards sometime :D

  • @sachinrawat4539
    @sachinrawat4539 Рік тому

    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

  • @jackdanyal4329
    @jackdanyal4329 Рік тому +6

    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.

    • @adilamrani2694
      @adilamrani2694 11 місяців тому +3

      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.

    • @alissonvieira6903
      @alissonvieira6903 3 місяці тому

      Yeah, good point.

  • @user-hz3tr9bu1h
    @user-hz3tr9bu1h 3 місяці тому +1

    But why a lot of projects have microservises on Go instead of Java

  • @kienha9036
    @kienha9036 Рік тому +6

    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.

    • @medaliboulaamail6491
      @medaliboulaamail6491 9 місяців тому

      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

  • @jofla
    @jofla Рік тому +2

    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

    • @AntonPutra
      @AntonPutra  Рік тому +2

      Right now my favorite is rust book =)

  • @linkernick5379
    @linkernick5379 4 місяці тому +1

    Very nicely presented, thank you.

  • @abe1
    @abe1 Рік тому +3

    Your videos are awesome 😁

  • @EgorKartashov
    @EgorKartashov Рік тому +8

    Can you please compare perfomance between Go and .NET 7?

    • @AntonPutra
      @AntonPutra  Рік тому +2

      Sure

    • @metaltyphoon
      @metaltyphoon Рік тому

      @@AntonPutra make sure to use minimal apis and not controller based stuff

  • @cetaepsilon
    @cetaepsilon Рік тому

    An underappreciated fact of JVM is that it does optimization for long term process. So 5:47 makes sense.

  • @user-qk5ok7lo3r
    @user-qk5ok7lo3r Рік тому

    Can you run the same test with spring3 and graalvm native image?

  • @phyohtetpaing44
    @phyohtetpaing44 Рік тому +6

    Sir request for Rust(Actix web ) vs Rust (GRPC) in kubernetes

  • @pixobit5882
    @pixobit5882 Рік тому +1

    "what does your tech stack look like?"
    Anton: Yes.

  • @OnliDM
    @OnliDM Місяць тому +1

    Would be interesting to see Java 21 compiled to native binary with GraalVM.

    • @AntonPutra
      @AntonPutra  Місяць тому +2

      actually working on it, go vs java (quarkus), which uses GraalVM

  • @knm080xg12r6j991jhgt
    @knm080xg12r6j991jhgt Рік тому +2

    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.

  • @adel8206
    @adel8206 Рік тому +10

    In the second test, the go code performs badly because you didn't release the file descriptors associated with the s3 image download connections

    • @AntonPutra
      @AntonPutra  Рік тому

      Yeap, thanks for feedback. I'll fix it for the new tests..

    • @jonnyd6087
      @jonnyd6087 Рік тому

      Interesting! What do you mean by release?

    • @haophan2280
      @haophan2280 Рік тому

      @@AntonPutra how about the new tests ? can you send me the link?

  • @TheExcentro
    @TheExcentro Рік тому +7

    Nice test :) Slowest java framework vs one of the fastest go's...

    • @AntonPutra
      @AntonPutra  Рік тому

      =)

    • @jonnyd6087
      @jonnyd6087 Рік тому

      Is spring the slowest java framework? I thought it was the #1

  • @AntonPutra
    @AntonPutra  Рік тому +2

    ❤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

  • @yakomisar
    @yakomisar Рік тому

    Антон, what is the amount of CPUs in this test?

    • @AntonPutra
      @AntonPutra  Рік тому

      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

    • @yakomisar
      @yakomisar Рік тому

      @@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.

  • @RobertGherlan
    @RobertGherlan Рік тому +14

    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.

    • @terrormapu
      @terrormapu Рік тому +2

      Yes the JVM is quite competitive

    • @AntonPutra
      @AntonPutra  Рік тому +1

      Thanks Robert, I'll keep it in mind

    • @NicolasdeJong
      @NicolasdeJong Рік тому +1

      Or use Java 19 which has virtual threads and so has a similar performance boost as switching to webflux.

    • @renbangbprd7236
      @renbangbprd7236 Рік тому

      @@NicolasdeJong Virtual Thread is still in preview

    • @knm080xg12r6j991jhgt
      @knm080xg12r6j991jhgt Рік тому

      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.

  • @unpub2
    @unpub2 Рік тому +1

    Кто нибудь напишите какой итог то? Кто выиграл?

  • @malexejev
    @malexejev Рік тому +5

    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
      @AntonPutra  Рік тому

      Thanks! It's more about ecosystem

    • @jonnyd6087
      @jonnyd6087 Рік тому +1

      ​@@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?

  • @Rogueixpresents
    @Rogueixpresents Рік тому +1

    Hey can you do Python fastapi vs nests?

  • @rochaaraujo9320
    @rochaaraujo9320 22 дні тому

    Java needs to fine tunning memory and spring. This will help with performance.

  • @seanknowles9985
    @seanknowles9985 Рік тому

    Whats more interesting is Golang vs Kotlin Native (Ktor server)

  • @17TheVIP
    @17TheVIP Рік тому +3

    Spring boot vs quarkus

  • @yasharjavdani4173
    @yasharjavdani4173 11 місяців тому

    Why u use spring. Go compare officefloor with fiber

  • @miracleinnocent2649
    @miracleinnocent2649 Рік тому +1

    Honestly Fiber is not that common cause of its performance Gin would be better

    • @AntonPutra
      @AntonPutra  Рік тому +1

      Well, based on the feedback on my previous video (go vs rust), no one likes gin anymore =)

  • @Quraan.114
    @Quraan.114 Рік тому +1

    You are using a bad array definition in java which is eating the stack memory

    • @AntonPutra
      @AntonPutra  Рік тому

      Any suggestions in the current context?

  • @sunhsiang6644
    @sunhsiang6644 Рік тому +2

    Next time make java native vs golang

    • @AntonPutra
      @AntonPutra  Рік тому

      What is java native?

    • @Nick-yd3rc
      @Nick-yd3rc Рік тому

      @@AntonPutra likely GraalVM built native images as I mentioned in my comment

    • @ivandenysenko
      @ivandenysenko Рік тому

      I am also curious about the results.

    • @jonnyd6087
      @jonnyd6087 Рік тому

      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.

  • @metaltyphoon
    @metaltyphoon Рік тому

    Dotnet minimal apis vs java!

  • @curio78
    @curio78 8 днів тому

    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.

    • @AntonPutra
      @AntonPutra  7 днів тому

      thanks for your feedback, wondering what do you think about Quarkus and compiling to native code?

  • @gordonfreimann
    @gordonfreimann Рік тому

    try echo Instead of fiber

  • @W0rldBr3aker
    @W0rldBr3aker Рік тому +2

    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.

    • @AntonPutra
      @AntonPutra  Рік тому +1

      I appreciate your feedback! Quarkus is coming soon.

  • @lilith1504
    @lilith1504 Рік тому

    Hey guy, a serious problem, if you're still using Lastpass, get off it forever. Move to anywhere else, idc, stop using Lastpass

    • @AntonPutra
      @AntonPutra  Рік тому

      Thanks, about to create tutorial how to host your own password manager!

  • @nissi2005
    @nissi2005 Рік тому

    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"));