epoll VS select

好久不见. 提交于 2019-12-19 06:19:44

问题


I have read a couple of networking books to get some idea of differences between epoll and select but they only covered this concepts slightly. I will be appreciated if you guys can provide me the key differences in details.

Thanks in advance


回答1:


select is the standard Unix facility for doing asynchronous IO. Its programming interface is quirky, and its implementation in most Unixes is mediocre at best. It also imposes a limit on the maximum number of descriptors a process can watch, which is inconvenient in an application. Regarding efficiency, the performance of select usually degrades linearly with the number of descriptors.

epoll is a huge improvement over select in terms of programming interface and efficiency, but is only provided in Linux starting from version 2.6. Other Unixes have their specialised calls, too.




回答2:


select always delivery descriptors to kernel when calling select().
But epoll delivery the descriptor once when calling epoll_ctl() and get events by calling epoll_wait().

And loop 0 to max_descriptor for checking events when using select.
But loop for event occured descriptors for checking events when using epoll.

These makes the difference in performance.

And select has a limit of maximum number of descriptors because it use bit array.
But epoll don't have a limit because it use structure array.

And select exists in most of platforms (windows, linux, unix, bsd)
But epoll exists only in linux.
Of course, there exists replacements of epoll in other platforms (IOCP in windows, kqueue in bsd, etc..)



来源:https://stackoverflow.com/questions/6303507/epoll-vs-select

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!