Linux OS Internals (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
How does `epoll` differ from `select` and `poll`?
senior LevelSystem Design
In Simple Words: The foundation of high-concurrency web servers (Nginx, Node.js, Redis):
select/poll(Ancient - $O(N)$): Every time an event occurs, the kernel returns the entire list of sockets. The application must iterate through all 10,000 sockets sequentially to find which one has data. Slow and limited.epoll(Modern Linux - $O(1)$):- Uses an internal Red-Black tree to monitor file descriptors.
- When an event occurs on a socket, a hardware interrupt appends it directly to a Ready List.
epoll_wait()returns only the active sockets that have data, delivering constant $O(1)$ performance!