Comparison of Rust async and Linux thread context switch time and memory use
1–10 of 201 posts
Re: Comparison of Rust async and Linux thread context switch time and memory use
#2Re: Comparison of Rust async and Linux thread context switch time and memory use
#3How does Rust async compare to Goroutine, Erlang threads, Javascript async, Java async in performance and memory usage? Is there any benchmarks for that?
Re: Comparison of Rust async and Linux thread context switch time and memory use
#4Re: Comparison of Rust async and Linux thread context switch time and memory use
#5Re: Comparison of Rust async and Linux thread context switch time and memory use
#6Quickest summary: Rust async is >3x faster and lighter than Linux threads. This is a great accomplishment for Rust.
Re: Comparison of Rust async and Linux thread context switch time and memory use
#7Think about it this way—if you have a user-space thread which wakes up due to I/O readiness, then this means that the relevant kernel thread woke up from epoll_wait() or something similar. With blocking I/O, you call read(), and the kernel wakes up your thread when the read() completes. With non-blocking I/O, you call read(), get EAGAIN, call epoll_wait(), the kernel wakes up your thread when data is ready, and then you call read() a second time.
In both scenarios, you’re calling a blocking system call and waking up the thread later.
Of course, there are scenarios when epoll_wait() returns multiple events, which reduces the number of context switches. But the general result is that it’s not always easy to beat blocking I/O and kernel threads.
Re: Comparison of Rust async and Linux thread context switch time and memory use
#8Re: Comparison of Rust async and Linux thread context switch time and memory use
#9I am not surprised that the cost of context switching due to I/O readiness can often be roughly equal between async tasks and kernel threads. Normal blocking I/O can be surprisingly efficient because of various factors, such as a reduced need for system calls. Think about it this way—if you have a user-space thread which wakes up due to I/O readiness, then this means that the relevant kernel thread woke up from epoll…
Re: Comparison of Rust async and Linux thread context switch time and memory use
#10This is a big surprise.
If you look at the Techempower web benchmark [1], the performance of actix-web is about 20x higher than that of Rocket.
The common explanation is that actix-web is async and hence much faster than Rocket which relies on kernel context switching.
But if Rust async and kernel thread has the same switch time as shown by this benchmark, then why is actix-web so much faster than Rocket?
[1] https://www.techempower.com/benchmarks/#section=data-r20&hw=...