Are there some simple rules of thumb when to use poll vs. epoll in a low-latency environment? epoll should have higher overhead if only few of file-descriptors is monitored. Please, give some insight, answers "check it yourself" put elsewhere.
Both of them potentially trigger on a single event. However, with poll, the user then has no choice but to iterate thru the entire list submitted to find the events, whereas with epoll you get a list returned containing only the actual events.
Poll System callpoll( ) is more efficient for large-valued file descriptors. Imagine watching a single file descriptor with the value 900 via select()—the kernel would have to check each bit of each passed-in set, up to the 900th bit.
Always use poll unless all of the following are satisfied:
epoll or you provide a fallback for systems that don't.epoll list is just as expensive as a poll operation, since it requires entering/leaving kernelspace).First of all, poll(2) is only level-triggered, but epoll(4) can be used as either edge- or level-triggered interface.
Now complexity: poll complexity regarding number of watched descriptors (fds) is O(n) as it scans all the fds every time when a 'ready' event occurs, epoll is basically O(1) as it doesn't do the linear scan over all the watched descriptors.
In terms of portability - as epoll is Linux-specific I would suggest checking out libev and libevent libraries. Also, check out Dan Kegel's excellent writeup: "The C10K problem".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With