Go vs. Rust: Performance Benchmark
Vložit
- čas přidán 12. 12. 2022
- 🔴 - 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...
#Rust #Golang #DevOps - Věda a technologie
🔴 - To support my channel, I’d like to offer Mentorship/On-the-Job Support/Consulting - me@antonputra.com
I added this to a comment of a comment, but thought I would add here. The Fibonacci implementations are not the same for your Go code and your Rust code. Your rust code does extra checking to avoid extra recursion calls. In my local testing, I can speed up Go's fibonacci implementation by like 50% just by using the same algorithm that you use in the Rust code.
Also, I can further improve the Go code for fibonacci where it's blazing fast if I rewrite the recursive function such that it can make use of tail call optimizations. I get it's there to artificially simulate load, but I wouldn't want someone's conclusion to be that "Oh man, Go under load is 80% worse than Rust!" when it's a case of this artificial function.
All of this is to say, I don't disagree with your thesis statement that Rust is more performant that Go. Rust just is faster when it's time to run code when all things are considered equal, especially now with async/await.
Thanks ShiftEleven for the feedback!
also i don't see a json serialization in the rust code for post method. in go code you are making a json serialization on post method with c.JSON.
I knew there was something like that haha Thanks! Now I don't need to check the code 🤣
Fibonacci functions are not even mathematically equivalent e.g. rust_fib(n) == go_fib(n) does not hold for all values of n since go uses 0 and 1 for the base case, while rust uses 1 and 2. Because of that rust version will also overflow/panic on fib(0), not a rusty way at all. Rust is a wonderful language indeed, but can we please prove it with proper science
@@oscarpinochet Rocket's Json type used in the handler automatically serializes. This is something basically every web framework in Rust offers as a return type in handlers.
as you've rightly noted - it's more about comparing gin vs rocket, than rust vs go, but still, thanks, quite insightful
well except fibonacci
@@AntonPutra My other comment disappeared, but the fibonacci algorithms aren't the same. The Rust algorithm handles a few other cases that when I add that same logic to Go, the Go implementation runs in half the time.
@@shifteleven Thanks, I got your point
This shows nothing yes go is slower than rust nothing new but 80 is such a big no no
this test is not accurate at all
I appreciate your effort in making and publishing this video. I appreciate the way you compared.
Thanks Uday!
Your videos are a godsend, thank you so much. Absolutely brilliant work! I wish you were in my team
Thanks =)
Wow. Impressive experiment. Loved the video! You've earned a subscriber :)
Thanks Ali!
Great content man! Appreciate it.
Thanks Kyrylo!
❤Go (Golang) vs Java: czcams.com/video/8CiErLxdaA8/video.html
❤Go (Golang) vs Node JS - czcams.com/video/ntMKNlESCpM/video.html
❤AWS Lambda Go vs. Node.js - czcams.com/video/kJ4gfoe7gPQ/video.html
❤AWS Lambda Python vs. Node.js - czcams.com/video/B_OOim6XrI4/video.html
Thanks for the great work!
As mentioned in other comments, Fiber, being based on fasthttp will be more interesting for the comparison and at the end of the day, perf and resource consumption are just factors that need to be crossed with speed of development and maintainability 😊
Thanks Abderrahmane! I tested fiber, it's much faster..
It would be better with fiber vs axum
Thank you for knowledge sharing, Anton
welcome =)
wow, just awesome video, thank you
Thanks fprotimaru!
Great content!
Thanks Renato!
Really great video Anton. Very quick but thorough explanation of how you built and ran this experiment. The findings are consistent with my expectations as another new student of Rust. I am using Rust on microcontrollers and it produces insanely efficient and safe code (as long as you stay away from much unsafe code). The learning code is steep but the payoffs are real and valuable.
Thanks Rich for the feedback. Agree the learning curve is much steeper but it's worth it!
Would be nice to see this with some different frameworks and endpoints that do binary serialisation/deserialisation, etc.
Then maybe perf test it with Gatling or similar tools.
Thanks, working on one with grpc (serialisation/deserialisation) & rest/json
❤Performance Benchmarks Playlist - czcams.com/play/PLiMWaCMwGJXl-h2RgOSpdO-pQaSRwlVjd.html
so informative in 6 mins. great!!!!
Thanks Emily!
so few folks seem to care about efficient software these days. happy to see this comparison being done.
Yeah, but rust has a much steeper learning curve..
Hi Anton! Thank you for the video, very interesting. Seems there is a small mistaking potentially making tests on the same node since the antiAffinity rules do not force running apps on different nodes. And you did not checked the apps are running on different nodes.
Thanks Ilya!
thanks for the video
Welcome!
Awesome !
Thanks =)
Fantastic test!!!!! Showwww!!!!! 👏👏👏👏👏💪👊👊👊
😅
Great comparison, btw can you benchmark same logic with nodejs and java spring? It will be very useful when I choose which lang is performant or not.
Go is much better than Node and Rust is much better than Go but its harder to learn
100%
For sure, just need to come up with interesting scenarios..
@@AntonPutra Hi Anton.. Beautiful demo.. May be the same example calculations could be used to benchmark spring and node as well.. as all the remaining setup will remain mostly unchanged.
very interesting video!
Thanks Habibi!
Useful video, thanks for sharing 👍
❤️
Resource consumption are just factors that need to be crossed with speed of development, maintainability and simplicity.
If your peak priority is just performance irrespective of other factors then Rust is a good choice.
💯
It would be interesting to see if there is more memory bandwidth usage in Rust.
ok
Wow, I did not expect there to be this big of a difference. In my mind (purely based on reputation), golang was already pretty efficient, but this feels like comparing python with any other language, where rust comes out well and truly on top. Definitely worth exploring rust further. I'd be interested to see how a more involved use case including database access (pgsql or mongo) would pan out. My expectation is that the difference will be less, but it's still nice to explore the quality of database clients for example.
Thanks for this.
Thanks Michael for the feedback. I'm working on the test that includes the postgres. By the way, somehow aws lambda written in go was faster, based on my previous benchmark...
Be careful with this conclusion - the implementations of Fibonacci are not the same so possibly the difference is smaller than you might expect based on these results.
@@mmmhorsesteaks Yeah, ideally you'd want an API to do a bunch of realistic stuff, like some file IO, some list sorting, a database call, and maybe even object transformations. In any case, this was a very solid test, and it matches some other results I found meanwhile.
would you mind doing Go vs. Node / Python / PHP?
Sure
Yes please 🙏
up
Would be amazing to see Deno and Bun runtimes from the Javascript world added to this to see how they compare..
Thanks for the feedback, I'll definitely test them!
Might get into Rust now that I just watched your video, thanks.
Not many production ready frameworks/docs…
@@AntonPutra I know but still, very interesting. What about concurrency though? which one do you think is better?
@@rwmusic8126 It seems the tokio crate is mostly used for concurrency. I'm planning to test it as well sometime in the future..
Would've been awesome video if you included NodeJS & Python to see the entire picture if you're mentioning environment friendliness and cost savings.
Thanks Shinebayar, I'll definitely include node and python in the future videos! Another one is coming in a couple of days.
@@AntonPutra sounds good. Subbed for that.
@@AntonPutra please include .net also.
Can you do same benchs with same fibbo in both lang and fiber instead gin ? :O looks good
I'll use fiber next
Would be nice to compare Nim with Rust. Knowing that Nim is much more concise and expressive then Go it would be a nice comparaison between two performant yet opposite languages
Thanks Alexandre, I'll take a look!
Great Video 📹 as always ,as you mentioned nginx ingress controller provides all application level metrics, it means I should not implement any apm for my application example datadog apm?
Thanks, not all metrics, but you still should expose some application specific metrics
@@AntonPutra Thanks for the reply, do you have any video, as per you mentioned "some application specific metrics" or can you can you please create? thanks
Would be cool if you can optimize the CPU intensive codes for both based on comments and make a sequel.
Thanks Misgana, yes working it =)
Hi Anton. Great videos. Really deep diving stuff! Very enjoyable & in many cases, very practical
Re: latency: Rust has better latency? (~5m47s) diff is 0.01ms (4.53 vs 4.52 & 4.98 vs 4.97). Well within error function range of switching time between virtual cores/memory eviction & processing sequence of exposed Prometheus; I'd call that even. Like you said it's really not about Rust vs Go here but the underlying REST libraries.
Having said that, Rust does have an edge, if it is slight in some cases (not all); But mass adoption of Rust vs "easier" languages (not vs Go) is not too dissimilar from learning Assembly vs C (BTW - worked with both; much older!); I'm not holding my breath.
Thank you, Fadi, for the feedback! It's mostly framework comparisons, but some may find it helpful. I don't like purely algorithmic benchmarks; I find them not practical.
This is my final tipping point. I am now inclined to learn rust.
It's better to start now =)
@@AntonPutra yep
How about using f-stack DPDK? I think this is the most most faster way. I want to see the test thank you ❤
Thanks, I'll take a look!
Could you also do this for rust vs C# ? I know it is silly but it would be a "nice to have" to convince some centerpiece folks ;)
well maybe in the future working on full courses tight now
I would suggest to use the same algorithm in both languages for calculating fibonacci number
Go implementation
```
func FibonacciDP(n int) int {
if n
Ok thanks!
how would express and fastapi/flask perform in these benchmarks?
Working on, but with fiber..
How's the performance of Istio vs LinkerD vs NATS (for NATS, request response only) for multi-region?
Coming soon! multi regions is too expensive for me to run =)
Other important info, we tested ALL our Go services on my Company, and we found that Go Works better with one entire CPU on the workloads config, i didnt see witch value was on your teste,but would be important
Got it, I'll keep it in mind for the next time.
когда с лёгкостью понимаешь каждое слово))
😅
Hello, great video. I’m going to deploy my app, can I use your configs? Should I remove something? I thought to use Baas, like appwrite, it is hard to me with the decision
appwrite is my favorite
Of course you can use any of my code! It's under MIT =)
Can you do another test with Go but use Fiber instead of Gin? cuz gin is a full web framework and fiber it's just lighter form of Gin. The Go stats seemed a bit thicker imo cuz of the Gin web framework you know? Cheers
Thanks Skoozle for the suggestion, I'll use Fiber for my next video
Hello, thanks for the video, but do you validate the request response and response code? Rust might be quick but is the math correct?
I use k6 to run the test and validate the response code.
k6.io/
@@AntonPutra 100% OK Response on rust and go ? no timeouts ? no dropped packets ?
@@adrustamm5828 cpu usage was only 80 percent, for simple programs I wouldn't expect to see errors or timeouts at 80 percent. Also it was p99, so there is always some request that can escape
@@angelbythewings I ve done a some stress tests with locust and I can tell you, errors and timeouts are there
Being easy to learn is really important for the companies. I think that's a reason for the low adherence for rust over go( go is really easy to learn)
Agree, go is much more beginner friendly!
You should have used native net package for building webserver in go instead of gin.
Yeah, but wanted to compare most popular frameworks..
@@AntonPutra can you also compare it with java springboot or other suitable java based backend framework ?
@@RudraSingh-pb5ls Java won't even clear the qualification round
@@angelbythewings why ? Just asking cause i have limited knowledge
@@RudraSingh-pb5ls Java is too resource intensive, I used to like java for how rich the development environment is, but as soon as you start to scale up, it starts adding to the cost considerably. It is very resource intensive. for comparison rust will take less than 10% of the resources that Java needs even for something as simple as a web server. both in terms of cpu cycles and memory. Now think of running micro services where you have 10-20 instances. you get the idea....
do more with c++ please, (go, rust and c++)
💯
Can we try fiber. Subscribed. Nice video
Sure, I'll use it next time
"saving environment" is a huge point here, and we don't even compare to most common environment polluters - Java & C#. Yes, we have to migrate apps with big loads to Rust, to save the planet. ASAP! I did it personally, gain not without pain, but the results have been jaw dropping.
😅
Should compare Actix vs Fiber. Gin is not known for its performance
Indeed exactly what I was thinking
Fiber does not implement standard httpHandler of go. Besides, Fiber does not support http2.
I tested Fiber, it's much faster! I'll use it in my next benchmarks for sure!
@@AntonPutra Try Echo and Chi too
The Fibonacci algorithm you used is based on recursion and everytime a recursive call is placed a new function is called in the function stack which means it also context switches the previous function and it takes a lot of time. Ideally you don't want to use recursion for simple tasks that can be done in a loop. Use recursion to solve problems meant for recursion. If you implement the same function through loop, i am willing to bet you that you'll lose most of the CPU execution time.
What would you recommend to simulate CPU load in different languages?
@@AntonPutra You're trying to simulate server load, so basically you fetch a document from storage do some computation that modifies the document and then send it to the client(ideally what most web servers would do)
@@swarnavasamanta2628 thanks
In order to get things working locally, can one just simply apply the yaml to a local K8s cluster and load the Grafana dashboards?
well, yes you can just make sure you have enough resource for each app - github.com/antonputra/tutorials/blob/main/lessons/138/go-app/deploy/deployment.yaml#L23-L29 as well as other components including prometheus, grafanam ingress etc
Очень информативно
spasibo =)
Ты использовал Gin, а как на счет Fiber?
I'll check it out
было бы интересно посмотреть crystal в аналогичном тесте
Spasibo za feedback!
C# dotnet? Why texhscene ignores these in benchmarks?
Sure, sometime in the future!
Why is the Rust logo so angry?
It's a revanche =)
I would love to see Actix performance instead of Rocket heheh
Noted =)
How does Scala compare to both Rust and Go?
share 2nd place
@@AntonPutra Do you mean it would be slower and consume more CPU/Memory than both Go and Rust when attempting this REST API setup?
I'm curious if Twitter should use Rust/Go instead of Scala for certain parts of their backend such API related ones
@@AnimexBoy7 To be honest I don't know. I only used scala when I had to write data pipelines with spark. Application is very different what typically rust and go used
Well... 15% difference may or not be a dealbreaker. Sometimes a better EC2 instance is cheaper than a Rust rewrite. It's counter-intuitive that Docker itself is written in Go whilst Redis is pure C.
Thanks for feedback
can you do rust vs C++ please?
I kinda did it already, while testing Istio (envoy based on c++) vs linkerd (rust based proxy).
what command is hey? is it app?or?
It’s a load generating tool, you can find it by googling hey GitHub, it’s written in go by the way. Happy new year! :)
why didnt you used fiber?
I did in another test, it's much faster =)
Well, by the comments below we can agree that it would be nice a part two using the same algorithm (it could the fibonacci one) in native rust and go.
Sure =)
Cool video, but fyi, rocket is not getting many updates and people dont use it much anymore, the rust web servers that have become the standard are axum and actix
Thanks echoptic! I'll try them next time..
As a backend developer, I want to learn a new programming language. Between Rust and Golang, which one do you recommend?
Thanks
If you want to be employed now you should learn Go, there are not a lot of jobs in Rust yet
I would have really like to adopt rust for my web development, but the learning curve was a bit too time consuming for me, and I find that go was very intuitive coming from php. Now if they came out with a framework with great documentation, tutorials, and was focused on MVC style concepts I may reconsider. But considering shopee and other major companies are using golang I think its probably fast enough for even multi-billion / trillion dollar companies.
Thanks for the feedback!
You Can try Graphul
@toast what APIs do you think are missing?
Axum has fantastic documentation, and is becoming the go-to http framework for rust
Actix-web is great too!
Considering the learning curve - go brings very good performance.
i was expecting you'll say rust =)
@@AntonPutra I mean comparing learning curve of rust and go, go still performs well with a much easier learning curve. You can get decent result in go, investing 10x less time than rust. To get a decent performance in rust involves learning many more new terms and concepts than golang.
@@dmitriyobidin6049 agree with that
Rocket is not born to fast. Must be compare with axum, actix or ntex to make sure your right 🎉
Okay, thanks for the feedback. Maybe in the future...
Could you do the same with async-graph rust vs c# hotcholate graphql?
Yes, in the future
I can help! If you need me to create both backends, please let me know, you would need just to modify and test since I’m not sure how to do it!
Do you have twitter?
I just tweeted you!
@@jonatthu sure, I need rust backend that downloads s3 image and saves the last modified date in postgress. Twitter twitter.com/antonvputra
Только вот не показал сколько запросов в секунду могут они обработать, мб Go больше запросов обрабатывает параллельно
i think i have it there
could you benchmark some popular messaging system, like rabbitmq, kafka, nats streaming, nsq
Yes, i was thinking about to compare data pipelines using different languages as well as to compare spark streaming and flink. comming soon..
Where is request per second comparison
It should be there
Прикольно
spasibo =)
rust is awesome but I would warn anyone about getting too complex in the code, because it can get very tricky there are a lot of deep mechanics going on in the language that you may or may not understand from the start, so you might end up with many reiterations on your code before it actually works well. Designing ahead is not as easy as it is in other languages where the compiler just lets you do "anything". The rust compiler is much more restrictive and usually there are only a few good ways to do what you want, and getting it right as a novice is even more unlikely than in other languages. So make sure you really understand the deeper concepts before relying on them in your designs.
Thanks for the feedback, I'll keep learning!
On pre-known entries llvm (rust) stores and returns the result, and does not recalculate it during runtime,
The app already knows what is the fibonacci(40) result
In real programs the entries are unpredictable, I don't know how Rust would perform in that case ??
fibonacci(url_param_number)
Got it, thanks for feedback!
it's not really a comparaison between go vs rust. When you use many things like framework, webserver with, it has always the impact of each others. But I appreciate your video as well
Thanks Duc! You're right it's more for entertainment.
you didn't tune GOGC and memory limit for go.
what's the best practise?
If you wanted to compare go vs rust, and not rocket vs gin, you had to use the most performant frameworks. A good candidate for go is fiber, which is based on fasthttp, but adds some almost zero cost sugar. Which framework is fastest on rust I don't know
Thanks Alexander, I've been using fiber for the last couple of weeks. It's very fast indeed.
as someone who is learning Go right now, I like seeing comparison like this
would love to see rust vs go vs php vs python
Thanks for the feedback, I still love go! But more to come =)
Rust's Rocket is nice, but I think in terms of performance, actix-web is even better.
Thanks Phil, I'll use Actix or Axum next time.
For real world application I highly recommend reading about why discord switched from go to rust.
It's out of date already, iirc discord did not move to nower go version which had included performance fixes on the garbage collector.
@@ResidentBio This is language design and cannot be out of date. Even with fixes. Go has a GC, Rust does not.
@@geeksy2278 They did not make a switch due to the existence of the GC. As far as I recall, they tried to tweak go's GC to their needs until they gave up and moved that service to RUST to not depends on a GC and regain some extra control they can afford. What's out of date from what I understand is the reason they did not find the performance fix they were looking for. The immediate next version of Go had a improvement that would have addressed their need. Or so was in paper according to one of Go's maintainer iirc.
I've read it, thanks.
Important nuance is scheduling. Go is preemptive whereas Rust is cooperative.
Thanks, I'll read about it!
I'm tittering on the edge of switching to Rust from Go
Go ecosystem is much more mature
@@AntonPutra very true i'll probably remain with go for the back and maybe convert the code into rust at a later date
Rocket is not really recommended as it doesn't get a lot of maintenance (bus factor of 1), there are better HTTP web frameworks, for example, Actix or Axum (I prefer Axum due to its integration with Tokio)
Thanks Alan, I'll use one of them for the next tutorial.
That strong Russian accent 😃
Thanks for benchmarking!
Welcome, happy new year! :)
Wow. Bravo. Thanks for proving Rust is a better choice.
It is but it has a steep learning curve!
@@AntonPutra That's right. But I also learned Rust in 1 month exactly. If you we have to passion to learn something then anything can be easy. Just lots of practice is required. Rust compiler is by far my best compiler I have ever used or known.
Please use actix instead of rocket
Sure, next time
Spikes are not a problem, free memory is important.
You don’t save money using rust, think about the time it takes to learn and to write programs in rust.
Also Golang concurrency is one of the best out there.
Agree, I love golang but still learning rust =)
Thats a lot false. The learning curve is high but borrow Checker will release software more reliable and safe than Go.
Классный видос
spasibo!
Doesn't everybody know that Rust is faster than GoLang?
Apparently AWS lambda doesn't =)
CPU should be very similar. Go does way better than JVM on memory. Just can't compete with C++ or Rust.
In theory, yes, but in practice, you use a bunch of libraries and frameworks that affect the efficiency
we're comparing unlike things here. the code really isnt the same on each app. Also i wouldnt save money converting something to rust from go because it takes like 5x longer to write something in rust than it does in go and i probably dont need that additional performance unless im doing some really specific systems programming at scale or something.
sure
do rust vs zig
Sure =)
I don't think Zig is ready to be used in production yet.
@@jaedson-barbosa Umm idk but there is a javascript runtime named Bun out there which is built on top of Zig
@@the_flask that still doesn't mean its ready to be in production..
@@amaanq8649 When i said that
next, compare Go to Java and/or C#, then Python. in my experience, Go is massively over sold.
Agree, working on it!
@@AntonPutra c# vs java vs go would be great
Instead of gin, try fiber.
I tried it in another video, it was equivalent to grpc calls so i had to redesign the test =)
But where rust at web development?