The difference between the epoll/select/poll of the multiplexed IO interface in Linux

Source: Internet
Author: User

The reason why select is less efficient than Epoll : Select is polling,Epoll is trigger, so it is efficient.

Select :

1.socket quantity limit :< Span style= "color: #333333;" > socketfd_ Setsize decided , kernel default 32*32=1024.

2. Operating Restrictions : by traversing the fd_setsize (1024x768 ) socket to complete the dispatch , regardless of which Socket is active , Go through it all over again .

Poll :

The number of 1.Socket is almost unlimited : The FD list for the Socket in this mode is saved by an array with an unlimited size ( default 4k).

2. operating limits : same as Select.

Epoll :

Unlimited number of 1.Socket : with Poll

2.Unlimited operation:Based on the reflection mode provided by the kernel,Have activesocket,socket No traversal polling .socket all active when ,< Span style= "color: #333333;" > this time all callback are all awakened .socket, So traversal is the simplest and most efficient way to implement .

For example :

ForIM Server , server and server are long links , but the number is not many , usually a 60\70 , such as the use of ICE This architecture is designed, but the requests are fairly frequent and dense, and it is not necessarily better to wake the callback by reflection than by using Select to traverse the process .

Forweb server , http short link request ,, > The site is a little more than thousands of requests every minute. , There's more socket,socket ,, so better .

Supports a process to open a large number of socket descriptors

SelectThe most intolerable is the opening of a processFdThere is a certain limit, by theFd_setsizesetting, the default value is1024。 For the tens of thousands of connections that need to be supportedim There are obviously too few servers. At this time you can choose to modify the macro and then recompile the kernel, but the data also pointed out that this will lead to a decline in network efficiency, two can choose a multi-process solution (traditional Apachelinux compared to the efficient synchronization between threads, it is not a perfect solution. But Epoll There is no such restriction, it supports 2048, 1gb10cat/proc/sys/fs/file-max > Look, in general this number and system memory are very large.

IO efficiency does not decrease linearly with increasing number of FD

of traditionalSelect/pollAnother deadly weakness is when you have a bigSocketcollection, but due to network latency,At any one time only part of theSocketIs "active", butSelect/pollEach invocation linearly scans the entire set, resulting in a linear decrease in efficiency. ButEpollThis problem does not exist, it is only for the "active"SocketTo operate---This is because in the kernel implementationEpollis based on eachFdAbove theCallbackfunction is implemented. Well, only the "active"SocketTo invoke it on its own initiative.CallbackFunctions, otherIdleStateSocketNo, at this point,EpollImplements a "pseudo"Aio, because at this time the impetusOsKernel. In someBenchmark , if all sockets are basically active --- such as a high-speed LAN environment,Epoll is no better than Select/poll What is the efficiency, conversely, if excessive use of epoll_ctl, efficiency compared to a slight decline. But once you use the idle connections to simulate a WAN environment,Epoll is far more efficient than select/poll .

Why select mode is inefficient

SelectMode inefficiency is caused bySelectRegardless of the operating system implementation, any kernel implements theSelectYou have to do round-robin to know theseSocketThe situation that it is going to consume Cpu. In addition, when you have a very large socketsocket is active " But every time you have to put all socket fill in a fd_set This also consumes some cpuselect Selectepoll relatively inefficient.

The Epoll scenario is a large number of sockets, but more active is not very high.

The difference between the epoll/select/poll of the multiplexed IO interface in Linux

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.