Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async IO on Linux: select, poll, and epoll #152

Open
luantranminh opened this issue Jan 25, 2023 · 0 comments
Open

Async IO on Linux: select, poll, and epoll #152

luantranminh opened this issue Jan 25, 2023 · 0 comments
Labels

Comments

@luantranminh
Copy link
Owner

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

First way: select & poll

poll and select fundamentally use the same code. They both call a lot of the same functions. One thing that the book mentioned in particular is that poll returns a larger set of possible results for file descriptors like POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR while select just tells you “there’s input / there’s output / there’s an error”.

select translates from poll’s more detailed results (like POLLWRBAND) into a general “you can write”

why don’t we use poll and select?

From the book:

On each call to select() or poll(), the kernel must check all of the specified file descriptors to see if they are ready. When monitoring a large number of file descriptors that are in a densely packed range, the timed required for this operation greatly outweights [the rest of the stuff they have to do]

what’s epoll?

The epoll group of system calls (epoll_create, epoll_ctl, epoll_wait) give the Linux kernel a list of file descriptors to track and ask for updates about activity on those file descriptors.

performance: select & poll vs epoll

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

Number of descriptors monitored (N) poll() CPU time (seconds) select() CPU time (seconds) epoll CPU time (seconds)
10 0.61 0.73 0.41
100 2.9 3.0 0.42
1000 35 35 0.53
10000 990 930 0.66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant