The difference between Epoll and poll, select

Source: Internet
Author: User
Tags epoll

Second, Epoll and select, poll difference

1. The biggest benefit compared to select and Poll,epoll is that it does not reduce efficiency as the number of monitoring FD increases. The implementation of select and poll in the kernel is handled by polling, the more the number of FD polled, the more natural time consuming.

2, the implementation of Epoll is based on callbacks, if the FD has the expected event occurs in the callback function to join the Epoll ready queue, that is, it only cares about "active" FD, and the number of FD Independent.

3, kernel/user space memory copy problem, how to let the kernel to notify the FD message to user space? In this issue select/poll took the memory copy method. The epoll uses a kernel and user-space shared memory approach.

4. Epoll not only tells the application that a i/0 event is coming, but also tells the application about the information that is populated by the application, so that the application can navigate directly to the event, without having to traverse the entire FD collection.

5, when the number of connected sockets is not too large, and these sockets are very active, then for Epoll has been calling the callback function (Epoll internal implementation more complex, more complex code logic), may not have the performance poll and select Good, Because the one-time traversal of the active file descriptor processing, in the case of a small number of connections, the performance is better, but in the case of large numbers of connections, Epoll obvious advantage.

Epoll the difference between epolllt (level trigger, default) and Epollet (Edge trigger) mode

1, Epolllt: Completely by the kernel Epoll drive, the application only needs to deal with the FDS returned from Epoll_wait, these FDS we think they are in a ready state. At this point Epoll can be thought of as a faster poll.

2, Epollet: In this mode, the system only notifies the application which FDS becomes ready state, once FD becomes ready state, Epoll will no longer pay attention to any state information of this FD (removed from epoll queue) until the application triggers Eagain state through read and write operations (non-blocking) , epoll that this FD becomes idle again, then epoll again attention to this FD state change (rejoin Epoll queue). With the return of Epoll_wait, the FDS in the queue is decreasing, so in large concurrent systems, Epollet is more advantageous, but the requirements for programmers are higher, as there may be problems with incomplete data reading, such as the following:

Suppose now that the other side sent 2k of data, and we first read 1k, and then call the epoll_wait, if it is the edge trigger, then this FD becomes ready to move from the Epoll queue, it is likely that epoll_wait will always block, ignoring the 1k data not yet read, At the same time, the other side is waiting for us to send a reply ACK, indicating that the data has been received, if it is a level trigger, then epoll_wait will also detect a readable event returned, we can continue to read the remaining 1k data.

The difference between Epoll and poll, select

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.