Hasty Briefsbeta

I/O Multiplexing (select vs. poll vs. epoll/kqueue)

4 days ago
  • #kqueue
  • #I/O multiplexing
  • #system calls
  • I/O multiplexing processes multiple input/output events from a single event loop using system calls like poll and select.
  • kqueue (MacOS) and epoll (Linux) are scalable I/O event notification mechanisms designed for high concurrency scenarios like web servers.
  • select has performance issues with O(n) runtime and can crash processes when handling file descriptors beyond FD_SETSIZE (1024).
  • poll, introduced in 1986, improved upon select by removing the 1024 fd limit and offering more event types, but still operates in O(n) time.
  • kqueue, introduced in 2000, is a scalable event notification interface that efficiently manages events using kevent structures and system calls.
  • The kevent structure identifies events with an <ident, filter> pair and uses flags to manage event registration and behavior.
  • The kevent system call allows adding, modifying, or deleting events and waiting for events to occur.
  • An event loop with kqueue involves creating a queue, registering events, and handling them as they occur in an infinite loop.