In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Select,poll,epoll is the mechanism of IO multiplexing. Icano multiplexing uses a mechanism to monitor multiple descriptors, and once a descriptor is ready (usually read-ready or write-ready), it can inform the program to read and write accordingly.
IO multiplexing is suitable for the following situations:
(1) when customers deal with multiple description words (usually interactive input and network socket interface), they must use Icano reuse.
(2) when a customer is dealing with multiple sockets at the same time, this is possible, but rarely occurs.
(3) if a TCP server has to deal with both the listening socket and the connected socket, it also needs to use IBO multiplexing.
(4) if a server has to deal with both TCP and UDP, it is generally necessary to use Imax O reuse.
(5) if a server has to deal with multiple services or protocols, it is generally necessary to use Imax O reuse.
Compared with multi-process and multi-thread technology, the biggest advantage of Icano multiplexing technology is that the system overhead is small, the system does not need to create processes / threads, and does not have to maintain these processes / threads, thus greatly reducing the system overhead.
Select:
Select is essentially the next step of processing by setting or checking the data structure that holds the fd flag bits. The disadvantages of this are:
1 the number of fd that can be monitored by a single process is limited
2 it is necessary to maintain a data structure for storing a large amount of fd, which makes it expensive for user space and kernel space to copy the structure.
(3) Linear scan when scanning socket
Poll
Poll is essentially no different from select. It copies the array passed in by the user to the kernel space, then queries the device status corresponding to each fd. If the device is ready, it adds an item in the device waiting queue and continues traversing. If no ready device is found after traversing all the fd, it suspends the current process until the device is ready or times out actively, and then it traverses the fd again after being woken up. This process has gone through many unnecessary traverses.
It has no limit on the maximum number of connections because it is stored based on linked lists, but there is also a drawback: a large number of fd arrays are copied between the user state and the kernel address space as a whole, whether such replication makes sense or not.
Another feature of poll is "horizontal trigger". If the fd is not processed after it is reported, the fd will be reported again the next time poll.
Epoll
Since epoll is an improvement on select and poll, it avoids the three shortcomings mentioned above.
Epoll supports horizontal trigger and edge trigger, the biggest feature is edge trigger, it only tells the process which fd has just become on demand, and will only be notified once.
On the replication issues mentioned earlier, epoll uses mmap to reduce replication overhead.
Another feature is that epoll uses the ready notification method of "events" to register the fd through epoll_ctl. Once the fd is ready, the kernel will use a callback mechanism similar to callback to activate the fd,epoll_wait to receive notifications.
Difference:
Selectpollepoll supports a maximum number of connections 1024 (x86) or 2048 (x64) unlimited IO efficiency for linear traversal per call, time complexity O (N) linear traversal per call, time complexity O (N) using "event" notification method, whenever the fd is ready, the callback function registered by the system will be called to put the ready fd into the rdllist, so that when the epoll_wait returns, we will get the ready fd. Time complexity O (1) fd copy every time select copies every time poll is copied every time epoll_ctl is called, it is copied into the kernel and saved by the kernel, and then every time epoll_wait is not copied
Summary:
(1) the select,poll implementation needs to poll all fd collections on its own until the device is ready, during which sleep and wake may be alternated several times. In fact, epoll also needs to call epoll_wait to continuously poll the ready list, and may alternate sleep and wake up many times during this period, but it calls the callback function when the device is ready, puts the ready fd into the ready list, and wakes up the process that goes to sleep in the epoll_wait. Although both sleep and alternate, select and poll traverse the entire fd collection when they are awake, while epoll only needs to determine whether the ready list is empty while awake, which saves a lot of CPU time. This is the performance improvement brought about by the callback mechanism.
(2) each time select,poll calls, it copies the fd collection from user mode to kernel mode, and hangs the current in the device waiting queue once, while epoll only copies once, and hangs current on the waiting queue only once (at the beginning of epoll_wait, note that the waiting queue here is not a device waiting queue, but a waiting queue defined internally by epoll). It can also save a lot of money.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.