The difference between select and epoll

Reprinted: https://blog.csdn.net/gymaisyl/article/details/83962671

 

select shortcomings: the

    limited number fd support:
    there is a maximum limit the number of individual processes can be monitored file descriptors, typically 1024, of course, can change the quantity, but the scanned file descriptor using select poll, the number of file descriptors the more, the poorer the performance; (in the linux kernel headers, such definitions: #define there is a maximum limit amount capable of monitoring a single process file descriptor, typically 1024, of course, may change the number, but using the select wheel the file descriptor inquiry scan mode, the more the number of file descriptors, the poorer the performance; (in the linux kernel headers, such definitions: #define
    __FD_SETSIZE 1024)

    each select call mode the user will be copied from the fd to memory state;
    kernel / user copy memory space problem, the kernel / user copy of the memory space problem, SELECT need to copy large amounts of data structure of a handle, a huge overhead;

    using a round-robin fashion, the kernel needs to traverse all passed in fd;
    select returns an array containing the entire handle, applications need to traverse the entire array can be made Which now handles an event has occurred; select returns an array containing the entire handle, applications need to traverse the entire array can be found which handles an event has occurred;

the SELECT only provides a function --select function and epoll provides three functions. epoll_create, epoll_ctl and epoll_wait;

    epoll_create is to create a epoll handle;
    epoll_ctl is registered to listen for the event type;
    epoll_wait is a wait event.

epoll select the original call is divided into three parts:

1) call epoll_create () to establish a epoll objects (allocation of resources to handle this object epoll file system)

2) call epoll_ctl add this one million connected to the socket epoll object

event 3) epoll_wait collect call occurred connected

to the first drawback, a limited number of FD:
  the epoll not have this limitation, FD is the upper limit of the maximum number it supports files can be opened, this number is much larger than 2048 in general, for example, 1GB of memory on the machine is about 10 about million and a specific number can cat / proc / sys / fs / file-max view, in general, this is a big number and the relationship between the system memory.
  
For the second drawback, the repeated copy fd from user mode memory state:
the epoll solutions epoll_ctl function. Every time a new event to register (designated EPOLL_CTL_ADD in epoll_ctl in) when epoll handle, the fd will all be copied into the kernel, rather than epoll_wait when a duplicate copy. epoll fd ensure that each copy only once in the whole process.

For the third drawback, the polling through all FD:
  the epoll not select a solution that every time the device turns corresponding to the current FD added to the wait queue, but only when the current hang over epoll_ctl (which again must be essential) and specify a callback function for each fd, when the device is ready, waiting for those who wake up waiting on the queue, it will call the callback function, and this callback function will be ready to join a ready list of fd). epoll_wait actually works is to look at the ready list, there is no ready fd (use schedule_timeout () to achieve sleep for a while, step 7 will be the effect of a judgment, and select implementations are similar).
---------------------
Disclaimer: This article is the original article CSDN bloggers' csdn * ", following the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/gymaisyl/article/details/83962671

Guess you like

Origin www.cnblogs.com/cppthomas/p/11319363.html