by asd4 · 3y ago · 0 comments
Many of the applications I write are like this, a daemon sitting in the background reacting to events. Making them single threaded means I can get rid of all the Arc and Mutex overhead (which is mostly syntactic at that point, but makes debugging and maintenance easier). Being able to do this is one of the things I love about Rust: only pay for what you need.
The article that this one is responding to calls out tokio and other async libraries for making it harder to get back to a simple single threaded architecture. Sure there is some hyperbole but I generally agree with the criticism.
Making everything more complex by default because its better for high throughput applications seems to be opposite of Rust's ideals.
IO bound means you spend most of your time waiting on an IO operation to complete. Usually writes are bound by the hardware (how fast your NIC is, how fast your storage is, ...), but reads are bounds by the hardware, but mostly by the "thing" that sends the data. So it's great you have a 10Gbps NIC, but if your database takes 10ms to run your query, you'll still be sitting for 10ms on your arse to read 1KB of data.
Throughput being IO-bound is indeed about the hardware, and the truth is that at the high end it's increasingly uncommon for things to be IO-bound, because our NICs and disks continue to improve while our CPU cycles have stagnated.
a. you cannot plan to read data from disk on demand, because it will take too long (still!), and it will almost certainly block
b. you cannot plan to write data to disk on demand, because it will take too long (still!) and it will almost certainly block
c. the bandwidth is still a limit on the amount of data that can be handled. It is much higher than it was with spinners, but there is still a limit.
for my data crunching project, one core processes about 500MB/s = 4Gb/s, and I have 64 cores..
What cloud providers give you for VMs is not the norm in the datacenters anymore.
[1] https://forums.servethehome.com/index.php?threads/cheap-40gb...
Web servers should be overwhelmingly synchronous.
They are the one easiest kind of application to just launch a lot more. Even on different machines. There are some limits on how many you can achieve but they aren't anything near low. (And when you finally reach them, you are much better rearchitecting your system than squeezing a marginal improvement due with asynchronous code.)
There's a lot to gain from non-blocking IO, so you can serve lots and lots of idle clients. But not much from asynchronous code. Honestly, I feel like the world has gone crazy.
https://docs.rs/tokio/latest/tokio/task/struct.LocalSet.html...
If you try to use axum in this way you'd still need to use send and sync all over the place.
The problem is that one may still want concurrency even when a single thread on a single CPU is enough.
I understand that it is less efficient but in the case you describe wouldn't paying for a few extra atomics be negligible anyway?