by wspeirs on 1/29/23, 12:40 PM with 47 comments
by yoshuaw on 1/29/23, 5:41 PM
In my opinion performance is always relative and dependent on the workload. Instead it’s worth looking more at which capabilities async Rust provides which aren’t present in non-async Rust. This includes ad-hoc cancellation, ad-hoc concurrency, and combining the two into things such as timeouts.
I wrote a post explaining this in detail a few months ago: https://blog.yoshuawuyts.com/why-async-rust/
by samsquire on 1/29/23, 2:06 PM
If you're serving a single connection with 1 thread then you're wasting that thread unless you do enough computation to fill that logical hardware thread's capacity.
In other words it's a good idea to use both together.
I wrote a 1:M:N scheduler in Rust, C and Java. It multiplexes N lightweight threads over M kernel threads and has 1 scheduler thread.
https://GitHub.com/samsquire/preemptible-thread
Nginx has multiple worker processes and an event loop in each I think.
There's no reason your event loop couldn't be on each thread.
I'm also thinking of separating recv and send on different threads so you can send and receive simultaneously.
by fnordpiglet on 1/29/23, 3:19 PM
I find it fascinating that LWT have come so far that this is a legitimate question. There was a time when async << threads << processes. But a lot of heroic good work went into bringing about this wonderful age.
by ThePhysicist on 1/29/23, 3:07 PM
I rewrote the same thing in Golang afterwards, took me maybe 10 % of the time and the code I produced was very readable and extremely fast. After that I'm a little burnt regarding Rust and have a hard time buying all the hype around it. I guess it has potential for embedded systems and other memory-constrained environments though, as Golang can't compete there right now due to the large size of the runtime, though there are projects like Tinygo that might eventually fill that gap as well. So I'm probably more hyped about Zig than Rust for now when it comes to next-gen languages.
by ngrilly on 1/29/23, 1:54 PM
by lr1970 on 1/29/23, 4:44 PM
by hota_mazi on 1/29/23, 6:56 PM
"If your tasks spend most of their time waiting, use async. If they spend most of their time running, use threads"
?
by AndrewGaspar on 1/29/23, 5:05 PM
by smabie on 1/29/23, 3:27 PM