I/O multiplexing¶
Category: Scheduling · Status: stub · Lessons: chapter 06, Async (planned)
One line: Asking the operating system to watch many sockets or file descriptors at once and report which are ready, so that one thread can serve thousands of connections.
Also called: epoll, kqueue, IOCP, select(2), poll(2).
How it connects¶
flowchart LR
n_async_runtime["Async runtime (executor and reactor)"]
n_event_loop["Event loop"]
n_io_multiplexing["I/O multiplexing"]
n_async_runtime -->|uses| n_io_multiplexing
n_event_loop -->|uses| n_io_multiplexing
classDef center stroke-width:3px
class n_io_multiplexing center
classDef outside stroke-dasharray: 4 3
class n_async_runtime,n_event_loop outside
- Is used by: Async runtime (executor and reactor), Event loop
- See also: Blocking and non-blocking calls
In each language¶
| Rust | Not in the standard library; the mio ↗ crate's Poll is backed by epoll, kqueue or IOCP, depending on the OS |
| C | POSIX poll ↗ and select ↗ |
| Java | Selector ↗ over non-blocking channels |
| Python | selectors ↗, whose DefaultSelector picks the most efficient mechanism on the platform |
| The operating system | epoll(7) ↗ on Linux, poll(2) ↗ everywhere; Windows I/O completion ports ↗ queue a packet when an I/O operation completes |
Where to read more¶
- In the books: Asynchronous Programming in Rust, Carl Fredrik Samson — ch. 3, 'Understanding OS-Backed Event Queues, System Calls, and Cross-Platform Abstractions'
- In the books: Python Concurrency with asyncio, Matthew Fowler — ch. 3, 'A first asyncio application' → 'Using the selectors module to build a socket event loop'
- In the books: Grokking Concurrency, Kirill Bobrov — ch. 11, 'Event-based concurrency' → 'I/O multiplexing'
- In the books: The Linux Programming Interface, Michael Kerrisk — ch. 63, 'Alternative I/O Models'
- In the books: The Go Programming Language, Alan A. A. Donovan, Brian W. Kernighan — ch. 8, 'Goroutines and Channels' → 'Multiplexing with select'
- In the books: Advanced Programming in the UNIX Environment, W. Richard Stevens, Stephen A. Rago — ch. 14, 'Advanced I/O' → 'I/O Multiplexing'
- Notes: Rust's Journey to Async/Await - Evented I/O non-blocking APIs - nginx ↗
- Reference: Wikipedia: epoll ↗