Comparison of SELECT, poll, Epoll for Linux network programming, and Epoll horizontal trigger (LT) and Edge Trigger (ET)

Source: Internet
Author: User
Tags epoll readable

Linux network communication has launched the Select, poll, Epoll three modes.

Select has the following three questions:

(1) Each time a select is called, the FD collection needs to be copied from the user state to the kernel state, which is very expensive when FD is very large.

(2) At the same time, each call to select requires the kernel to traverse all of the FD that is passed in, which is also very expensive when FD is very large.

(3) The number of file descriptors supported by Select is too small, the default is 1024.

Poll solves the third problem, select Save Descriptor FD's data structure is an array, poll changed to a linked list, breaking the number of FD limit.

But questions of the 1th and 2nd remain.

Epoll on the basis of poll, and solved the first two problems:

(1) For the first question, epoll each time a new event is registered to the Epoll handle (Epoll_ctl_add is specified in Epoll_ctl), all of the FD is copied into the kernel instead of being duplicated at epoll_wait time. This epoll guarantees that each FD will be copied only once throughout the process.

(2) For the second question, Epoll sets up a list of ready lists separately, when FD is ready (readable/writable) and placed in the Ready list. Epoll_wait only needs to traverse the ready list, without having to traverse all of the FD, thus saving a lot of CPU time.

Epoll has LT and et two operating modes, the default operating mode is LT (horizontal trigger), high-speed operation mode is ET (Edge trigger).

It is an FD that notifies the user as long as it is in a readable or writable state, and the user is notified when the ET is unreadable to be readable or not writable.

ET's call to the system is much less than LT, so et is a high-speed working mode with much higher efficiency.

When the user uses ET mode, the read/write FD must be read/written continuously (until the Eagain error is returned). Otherwise, if you do not read/write, the system will assume that the state has not changed, will not repeat the notification, so that the FD died.

Comparison of Select, poll, Epoll for Linux network programming, and Epoll horizontal trigger (LT) and Edge Trigger (ET)

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: info-contact@alibabacloud.com 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.