context-switch icon indicating copy to clipboard operation
context-switch copied to clipboard

I/O Multiplexing

Open ibraheemdev opened this issue 11 months ago • 0 comments
trafficstars

I was surprised to find that there is no mention made to the benefit of I/O multiplexing.

A context switch takes around 0.2µs between async tasks, versus 1.7µs between kernel threads. But this advantage goes away if the context switch is due to I/O readiness: both converge to 1.7µs.

The way the benchmarks are set up, from what I could tell, is such that I/O requests are fulfilled sequentially. This means that every call to epoll_wait corresponds to a single readiness event, i.e. a single context switch. This fails to consider scenarios where a large number of concurrent I/O operations allow the cost of the context switch to be amortized, i.e. calls to epoll_wait returning multiple readiness events in exchange for a single context switch.

In other words the cost of an I/O readiness switch may be the same, but an asynchronous server will pay the cost less due to I/O multiplexing. The wording of the quote ("but this advantage goes away") seems to suggest that the perceived benefit of async does not actually manifest in the case of I/O, which is not necessarily true.

ibraheemdev avatar Nov 21 '24 18:11 ibraheemdev