Comparison of select, poll, and epoll: Mechanisms, Complexity, and Practical Usage
This article compares the three I/O multiplexing mechanisms—select, poll, and epoll—detailing their time‑complexities, limitations, implementation details, trigger modes, and performance trade‑offs to help developers choose the most suitable method for different Linux networking scenarios.
select
select monitors multiple file descriptors by linearly scanning the entire fd set, resulting in O(n) time complexity; it is limited by FD_SETSIZE (typically 1024 on 32‑bit systems) and incurs significant copy overhead between user and kernel space.
poll
poll works similarly to select but stores the fd list in a linked list, eliminating the hard limit on the number of descriptors; however, it still suffers from O(n) linear scanning and copies the entire fd array between user and kernel space on each call.
epoll
epoll provides O(1) event notification by registering interest in file descriptors once via epoll_ctl and then waiting for readiness with epoll_wait ; it supports edge‑triggered (EPOLLET) and level‑triggered (EPOLLLT) modes, removes the descriptor limit, and reduces copying by using memory‑mapped buffers.
Key Differences
Maximum connections: select is limited by FD_SETSIZE, poll has no hard limit, epoll can handle tens of thousands of connections depending on system memory.
Scalability with many fds: select and poll degrade linearly as the fd count grows, while epoll processes only active fds, avoiding linear slowdown.
Message passing: select and poll copy data between kernel and user space; epoll shares a memory region, reducing copy overhead.
Implementation Highlights
select copies the fd_set from user to kernel, registers a callback with __pollwait , traverses all fds, and copies the result back; poll follows the same steps but uses a pollfd array and a linked‑list storage.
epoll registers each fd once via epoll_ctl , stores callbacks in the kernel, and epoll_wait simply checks a ready‑list, dramatically lowering CPU usage when many fds are idle.
When to Use Which
For a small number of connections or when all sockets are highly active, select or poll may perform adequately; for large‑scale servers with many idle connections, epoll offers superior efficiency and scalability.
References
https://www.cnblogs.com/zhaodahai/p/6831456.html https://www.cnblogs.com/sky-heaven/p/7011684.html
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.