TLDR: Go can reach 270k req/s where Rust can hit 400k req/s.
Go server
Let's go straight to buisness with a minimal server sample using...
For further actions, you may consider blocking this person and/or reporting abuse
I played with the code on my computer and got better performance with Go httprouter and even better results with Go fasthttp: gist.github.com/r0mdau/ac0f416d230...
Conclusion: whatever the language, take time to understand how the framework you use works and pick what fits best to you / team / project.
You had to use rust release target instead of debug
Thank you for the comment, I edited the results. 1: fasthttp, 2: actix, 3: httprouter
There is still one issue with the benchmark. FastHTTP doesn't perform any path matching against the template, hence have some benefits. I'd suggest to use raw hyper benchmark for rust instead of actix.
And please also enable the LTO in Cargo.toml
This code for hyper responds with exactly the same body and headers in size as fasthttp. On my computer, with LTO enabled, it performs much faster than go fasthttp.
fasthttp:
hyper:
Updated my gist adding Hyper, routing in fasthttp and giving my go and rustc versions in doc. I still find fasthttp the best performer with these codes: gist.github.com/r0mdau/ac0f416d230...
Seems a bit unfair to pit net/http to actix. try fasthttp instead.
Am I missing something? The Rust version uses async/await while the Go version does not use the equivalent(go routines).
Are you sure? It seems to me that the ListenAndServe() method spawns goroutines to handle incoming requests.
We should expect a performance difference for such a simple example. However most real world web apps are not so simple and differences in db queries etc could easily outweigh the choice of language.
I think Rust is almost always going to be faster than Go if both are equally optimised simply because it is somewhat closer to the metal. But how does the effort and expertise required to achieve such optimisation compare with each language? However I don't think rust should be seen as Go's primary competitor. Rather I think we should compare with Java, node.js, python, ruby, and C#. I expect Go would be quite competitive with all of those.
Let's also remember other factors like ease of maintaining a large codebase and hiring pool.
That said, I prefer Rust for its safety guarantees. The ease with which you can end up with data races or null pointers in Go just makes me nervous. I do see its appeal though. Simplicity is a worthy design goal.
You are right. I meant my comment to come off as more a question than a statement but I kinda failed there. I was on my phone and couldn't check the source code for the Go version. But you answered my question most thoroughly though. Thanks for the reply and article!
We'll be publishing a post soon about comparing Rust and Go in 2024, stay tuned here - packagemain.tech/
Rust for Gophers with John Arundel packagemain.tech/p/rust-for-gophers