

Memory usage of Ruby vs Rust
source link: https://pen.so/2022/05/30/ruby-vs-rust-memory-usage/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Memory usage of Ruby vs Rust
I currently work at Beam, and more specifically on the server-side API allowing our users to synchronize their data on all their devices. For privacy reasons, this API is E2EE and we don’t see anything except encrypted blobs. The private keys are stored on the user’s device.
This API is currently in Ruby and called through GraphQL and REST endpoints. This API will potentially manage a lot of data, and it became clear Ruby wouldn’t fit the need. It’s very hard to stream response, and Ruby’s memory usage is usually too high. And as a Ruby coder since 2005, it pains me to say it.
I spent the last year reading about Rust (and Go) on evenings and weekends, and prototyping code to get a feeling of the language and what it promises to deliver. We recently decided it would be time to now work on it day-time and start replacing endpoints. It’s far from being over yet, but I already have some feedback.
The first endpoint I’m rewriting is fetching rows from a pgsql database, and streaming results as JSON to the HTTP client. I’m testing this for over 50,000 rows and over 200MB of data. We are currently hosted on Heroku, and the Ruby instance has the following memory metrics.
It uses up to 2GB of memory, which is expected for a Rails stack.
And now the Rust metrics.
The Rust endpoint has been done using actix, sqlx, serde, and a few others.
It uses up to 4MB… About 500x time less. The benchmarks I did shows 30% speed improvements as well, which to be honest was deceptive. But the Rust instance runs on a different Heroku dyno, with a 10x smaller cost per month. Moving the Rust instance to the same Ruby instance didn’t improve speed, I guess the bottleneck is on our pgsql instance.
Our Ruby stack is doing a lot more for now, but it’s still impressive nonetheless. I have the feeling Rust will become very popular among server-side micro-services.
Recommend
-
53
Last week Red Hat introduced the open source framework Quarkus which promises fast boot times and low memory usages. This makes Quarkus interesting for Java wor...
-
13
-
7
Reducing Memory Usage in Ruby 2018-01-23 @ 13:36 I’ve been working on building a compacting garbage collector in R...
-
13
Reduce Rails Memory Usage, Fix Leaks, R14 and Save Money on Heroku Updated Jun 7, 2020 14 comments
-
5
June 17, 2020 PC Improving Memory Usage in Microsoft Edge ...
-
7
Docker Tutorial Understanding Container Memory Usage Jun 25, 2017 I know that it might seem like in 2017, in our new container centric world, that understanding memory usage on a per container basis isn't all...
-
7
Measuring Memory Usage in Rust @matklad, Dec 4, 2020 rust-analyzer is a new "IDE backend" for the Rust programming language. Support rust-analyzer on
-
13
BackendCables vs. malloc_trim, or yet another Ruby memory usage benchmarkMarch 19, 2019 Single line, big promise Memory usage has always been one of the most discussed performance-related topics i...
-
11
September 21, 2021Min ReadTaming Go’s Memory Usage, or How We Avoided Rewriting Our Client in RustMark GritterShare This Article...
-
12
How to investigate memory usage of your rust programMarch 18, 2022At Quickwit we have a mindset to create memory efficient and fast software, something that resonates with me personally. I love to create fast so...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK