Go (Golang) vs Java: Performance Benchmark

Поделиться
HTML-код
  • Опубликовано: 25 окт 2024

Комментарии • 150

  • @AntonPutra
    @AntonPutra  Год назад +3

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

  • @pompiuses
    @pompiuses Год назад +46

    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 Год назад +9

      @@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  Год назад +2

      Thanks pompiuses! I appreciate your feedback!

    • @petersburgh78
      @petersburgh78 Год назад +3

      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 Год назад

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

  • @gayanperera7273
    @gayanperera7273 8 месяцев назад +16

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

  • @biplovkc4100
    @biplovkc4100 Год назад +78

    lets settle java vs dotnet :D

    • @AntonPutra
      @AntonPutra  Год назад +7

      sure =)

    • @biplovkc4100
      @biplovkc4100 Год назад +1

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

    • @AntonPutra
      @AntonPutra  Год назад +1

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

  • @n1kk0n
    @n1kk0n Год назад +9

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

  • @awstherapy
    @awstherapy Год назад +6

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

  • @cetaepsilon
    @cetaepsilon Год назад +3

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

  • @primux2007
    @primux2007 Год назад +5

    I love this kind of videos, thank you.

  • @OnliDM
    @OnliDM 6 месяцев назад +4

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

    • @AntonPutra
      @AntonPutra  6 месяцев назад +2

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

  • @kienha9036
    @kienha9036 Год назад +9

    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 Год назад

      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

    • @gandalfthegrey2777
      @gandalfthegrey2777 Месяц назад

      is spring that resource heavy? Taking 50% memory where go only taking 6%?

    • @Toisen
      @Toisen Месяц назад +2

      ​​@@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
      @gandalfthegrey2777 Месяц назад

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

    • @Toisen
      @Toisen Месяц назад +2

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

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

  • @Бензини
    @Бензини 8 месяцев назад +2

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

  • @jackdanyal4329
    @jackdanyal4329 Год назад +9

    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 Год назад +4

      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 8 месяцев назад

      Yeah, good point.

  • @wildegor
    @wildegor Год назад +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

  • @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 =)

  • @matstark776
    @matstark776 Год назад +6

    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 Год назад +4

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

  • @AntonPutra
    @AntonPutra  Год назад +3

    ❤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

  • @phyohtetpaing44
    @phyohtetpaing44 Год назад +6

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

  • @omerkarahan2482
    @omerkarahan2482 Год назад +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  Год назад +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 Год назад

      @@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  Год назад +1

      @@omerkarahan2482 got it

  • @pixobit5882
    @pixobit5882 Год назад +1

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

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

    • @AntonPutra
      @AntonPutra  Год назад

      true

    • @maximodakila2873
      @maximodakila2873 4 месяца назад

      When GraalVM becomes mainstream, we don't need the JVM to run our Java apps in the cloud. That would level the playing field.

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

  • @dmitrikonnov922
    @dmitrikonnov922 Год назад +1

    Great job!

  • @adel8206
    @adel8206 Год назад +12

    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?

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

  • @rochaaraujo9320
    @rochaaraujo9320 5 месяцев назад

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

  • @linkernick5379
    @linkernick5379 9 месяцев назад +1

    Very nicely presented, thank you.

  • @TheExcentro
    @TheExcentro Год назад +7

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

    • @AntonPutra
      @AntonPutra  Год назад

      =)

    • @jonnyd6087
      @jonnyd6087 Год назад +2

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

    • @michaelm001
      @michaelm001 13 дней назад

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

  • @abe1
    @abe1 Год назад +3

    Your videos are awesome 😁

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

  • @Taurdil
    @Taurdil Год назад +6

    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 Год назад +8

      ​@@alexandrep4913 rust is so ridiculously complicated IMO

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

  • @mfc1190
    @mfc1190 Год назад +1

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

  • @unpub2
    @unpub2 Год назад +1

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

    • @AntonPutra
      @AntonPutra  Год назад +4

      ukraina =))

    • @aldspsa
      @aldspsa День назад

      @@AntonPutra вы из Украины?

  • @gregoriodia
    @gregoriodia 3 месяца назад

    This is not language, but frameworks (especially Go one he choose is not needed and slow as hell).

    • @AntonPutra
      @AntonPutra  3 месяца назад

      it's always framework :)

  • @Rogueixpresents
    @Rogueixpresents Год назад +1

    Hey can you do Python fastapi vs nests?

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

  • @Quraan.114
    @Quraan.114 Год назад +1

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

    • @AntonPutra
      @AntonPutra  Год назад +1

      Any suggestions in the current context?

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

  • @yasharjavdani4173
    @yasharjavdani4173 Год назад

    Why u use spring. Go compare officefloor with fiber

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

  • @ArpitRathore-k8k
    @ArpitRathore-k8k Год назад

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

  • @miracleinnocent2649
    @miracleinnocent2649 Год назад +1

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

    • @AntonPutra
      @AntonPutra  Год назад +2

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

  • @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!

  • @seanknowles9985
    @seanknowles9985 Год назад

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

  • @heshamyousef4819
    @heshamyousef4819 4 месяца назад

    I am extremely confused by the end of the video, which of both is better for DevOps?

    • @AntonPutra
      @AntonPutra  4 месяца назад +1

      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.

    • @heshamyousef4819
      @heshamyousef4819 4 месяца назад

      @@AntonPutra Thanks

  • @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 Год назад +1

      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.

  • @17TheVIP
    @17TheVIP Год назад +3

    Spring boot vs quarkus

  • @metaltyphoon
    @metaltyphoon Год назад

    Dotnet minimal apis vs java!

  • @gordonfreimann
    @gordonfreimann Год назад

    try echo Instead of fiber