select vs. poll vs. epoll
All 3 are used for I/O multiplexing: monitor multiple file descriptors to see whether I/O is possible on any of them.
epoll was meant to replace the older POSIX select and poll system calls.
Complexity and Scalability
- the older system calls operate in
O(n)time: every time you callselectorpoll, the kernel needs to check from scratch whether your file descriptors are available for writing. The kernel doesn’t remember the list of file descriptors it’s supposed to be monitoring. epolloperates inO(1)time. It doesn't do the linear scan over all the watched descriptors.epolluses a red-black tree (RB-tree) data structure to keep track of all file descriptors that are currently being monitored.epoll"scales well to large numbers of watched file descriptors."
Availablity and Portability
selectandpollare available on any Unix system.epollis Linux specific (available after version 2.5.44).pollis a POSIX standard interface, so use that when portability is required.
poll vs select
Given a list of file descriptors, they tell you which ones have data available to read/write to. select and poll fundamentally use the same code. poll returns a larget set of possible results for file descriptors like POLLRDNORM, POLLRDBAND, POLLIN, POLLHUP, POLLERR, while select just tells you there's input/output/error.
poll can perform better than select if you have a sparse set of file descriptors. poll takes a pollfd argument to specify which file descriptors to monitor; select takes bitsets and loops the whole range.
level-triggered vs edge-triggered
- level-triggered: get a list of every file descriptor you’re interested in that is readable.
- edge-triggered: get notifications every time a file descriptor becomes readable.
poll is only level-triggered, but epoll can be used as either edge- or level-triggered interface.
epoll
epoll_create: start epolling.epoll_ctl: tell the kernel file descriptors you’re interested in updates about.epoll_wait: wait for updates about the list of files you are interested in.epoll_wait()itself is a blocking interface. Whenever you callepoll_wait(), it blocks your thread/process until any of the monitored events happens on the registered descriptors. Either you ask epoll to monitor a non-blocking or blocking FD, epoll interface, itself, is still blocking-based
Where epoll is used
- node.js uses
libuv(which was written for the node.js project). - the
geventnetworking library in Python useslibev/libevent. - golang uses some custom code. This looks like it might be the implementation of network polling with
epollin the golang runtime – it’s only about 100 lines which is interesting. You can see the generalnetpollinterface,it’s implemented on BSDs withkqueueinstead. - Webservers also implement
epoll: Every time the webserver accept a connection with theacceptsystem call, and it gets a new file descriptor representing that connection. There may be thousands of connections open at the same time. You need to know when people send you new data on those connections, so you can process and respond to them.
- 32-bit vs 64-bit
- AES vs RSA
- Agent vs Agentless
- Annotations vs Decorators
- Terraform vs Ansible
- BASH vs ZSH
- BigQuery vs Bigtable
- Block Storage vs File Storage vs Object Storage
- Canvas vs SVG
- cgroupfs vs systemd
- Constructor vs Init() vs Factory
- Container Image vs Helm Chart vs OCI Bundle
- Containers vs Virtual Machines (VMs)
- C vs C++
- Java vs C++
- Rust vs C++
- crictl vs ctr
- Dagger vs Guice
- DMA vs RDMA
- DOM vs Virtual DOM vs Shadow DOM
- DQL vs DDL vs DCL vs DML
- eBPF vs Sidecar
- Flux vs Redux
- Full Disk Encryption vs Partition Encryption
- Gatekeeper vs OPA
- Google vs Open Source
- Why MCP uses JSON-RPC 2.0 instead of grpc
- gRPC vs OpenAPI
- gtag.js vs Google Tag Manager (GTM)
- Versus
- Kotlin vs Java
- Jetty vs Netty
- .js vs .jsx vs .ts vs .tsx
- Kata Containers vs KubeVirt
- Linux Namespace vs Kubernetes Namespace
- Linux vs BSD
- LLVM vs JVM
- Data Mining vs Machine Learning vs Artificial Intelligence vs Data Science
- Managed Kubernetes vs Self-managed Kubernetes
- Management Plane vs Control Plane vs Data Plane
- Microcontroller vs Microprocessor vs Computer
- MMU vs IOMMU
- Single-tenant vs Multi-tenant vs Multi-single-tenant
- Multithreading vs Multiprocessing vs Distributed Systems
- Node.js vs Erlang
- OCI Image vs Docker Image
- OCI vs CRI
- OpenSSH vs OpenSSL
- Pass-by-value vs Pass-by-reference
- Podman vs nerdctl
- POSIX vs SUS vs LSB
- Private Key vs Public Key vs Certificate
- Proto Edition 2024 vs Proto Edition 2023
- Proto2 vs Proto3 vs Proto Editions
- Message Queue vs PubSub
- React vs Flutter vs Angular
- REST vs SOAP
- RSA vs ECDSA
- select vs. poll vs. epoll
- SLI vs SLO vs SLA
- Spanner vs Bigtable
- Static Site Generation vs Server-side Rendering vs Client-side Rendering
- Stack based VM vs Register based VM
- Stateless vs Stateful
- Strong Consistency vs Eventual Consistency
- stubs vs mocks vs fakes
- Subroutines vs Coroutines vs Generators
- Software Engineer vs Site Reliability Engineer
- Symlinks vs Hard Links
- JAX vs Tensorflow
- Tensorflow vs PyTorch
- Terminal vs Shell
- Throttling vs Load Shedding
- Unix Domain Sockets vs Network Sockets
- Unix Domain Sockets vs Shared Memory
- URI vs URN vs URL vs URC
- Valkey vs Redis vs Memcached
- Vi vs Vim vs gVim vs Neovim
- WAL vs rollback journal

