Live data from Hacker News

Comparison of Rust async and Linux thread context switch time and memory use

github.com

51–60 of 201 posts

Re: Comparison of Rust async and Linux thread context switch time and memory use

#51

A meaningless comparison. Linux, being a preemptively multitasking OS, switches thread contexts regardless of what you're running. So the Rust async context switch is on top of the regular Linux context switch, not instead .

When you're in sub microsecond time scales, preemption events are relatively rare.

Re: Comparison of Rust async and Linux thread context switch time and memory use

#53
post #5

That's a huge help. I only need about 20 threads in Rust, some of which are compute-bound. So involving "async" is totally the wrong tool for the job. Goodbye, Tokio.

> So involving "async" is totally the wrong tool for the job. Sadly with so many things having gone async-first (or only) it’s become difficult not to end up with an async runtime anyway, or not be forced to use an async system. I wanted to build a small web-based tool for local, didn’t really find anything which was not async.

I’d happily take an async-by-default world over a world where some APIs only exist through blocking calls. A classically threaded program can easily block on a future, but wrapping a blocking call in an otherwise asynchronous program is complicated, expensive and error prone work.

Re: Comparison of Rust async and Linux thread context switch time and memory use

#54
post #35

Earlier quoted context omitted.

Then why is it that IO-heavy benchmarks such as the Techempower web benchmark are dominated by async frameworks? The fastest results there are all from async frameworks [1]. And among Rust frameworks the same pattern holds. The fastest Rust frameworks are async while a synchronous frmework such as Rocket is about 20x slower. [1] https://www.techempower.com/benchmarks/#section=data-r20&hw=... [2] https://www.techempow…

Those benchmarks measure one very specific scenario: serving lots of small requests concurrently. Async handles that well because that's exactly the scenario where a single epoll_wait() call will return lots of events.

Is there a different benchmark that demonstrates a scenario where synchronous syscalls are better suited?

Re: Comparison of Rust async and Linux thread context switch time and memory use

#55

> But this advantage goes away if the context switch is due to I/O readiness This is not at all a fair comparison unless you're using io_uring.

Good point - It’d be very interesting to see how io_uring changes those numbers if anyone has some time to make a fork / PR!

Re: Comparison of Rust async and Linux thread context switch time and memory use

#56
The discussion should feature prominently somewhere on top that the comparison is between the Tokio async runtime and Linux threads. Reason being, people not familiar with Rust may assume that the discussion applies to Rust async in general, when it doesn't necessarily. Sure, in practice Tokio is pretty close to being the de-facto async runtime in Rust. But it's not the only one, as Rust's async language constructs allow for different runtime implementations that may be optimized for different use cases.

Re: Comparison of Rust async and Linux thread context switch time and memory use

#58
post #40
post #20

Please don't mix nanoseconds and microseconds. This is just confusing to read. Stick to nanoseconds for everything.

ah, a fellow traveler - godspeed. what a sane, reasonable world we could have if nanosecond timestamps ruled supreme.

I wouldn't be so extreme, providers of '0' keys would flourish

Re: Comparison of Rust async and Linux thread context switch time and memory use

#59
To me it looks like the main advantage of async is memory usage, which is kind of expected because of the overhead of a thread. But if you do not need lots of thread it doesn't look like there is a huge benefit going async. Or do I miss something here?
Post reply on HN