tldr of a tldr: select, poll, epoll from Julia Evans

Reference: https://jvns.ca/blog/2017/06/03/async-io-on-linux--select--poll--and-epoll/

This is a summary of Julia Evans blogpost above^. Please visit the original link for a better explanation.

What we want

Instead of pinging kernel nonstop to ask for updates, we want the kernel to tell us when there are updates.

Polling

poll and select call the kernel to tell us with a polling mechanism. The kernel doesn’t remember which file descriptors to monitor, it only knows because we tell it, bypassing the file descriptors in the arguments. This takes time.

Terminology

  • level-triggered

Signal Driven I/O

signal-driven I/O - idk

epoll

  • epoll_create - tell kernel u wanna epoll

  • epoll_ctl - tell kernel which fd u want updates from. NOTE: this works for everything except regular files: e.g. sockets, pipes, FIFOs, POSIX msg queues, etc…

  • epoll_wait - wait for updates

Performance

In the book: The Linux Programming Interface, there’s a table comparing the performance for 100,000 monitoring operations:

  operations  |  poll  |  select   | epoll
10            |   0.61 |    0.73   | 0.41
100           |   2.9  |    3.0    | 0.42
1000          |  35    |   35      | 0.53
10000         | 990    |  930      | 0.66

More reading