In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
1 、 select
Select is essentially the next step of processing by setting or checking the data structure that holds the fd flag bits.
Disadvantages:
1) the number of fd that can be monitored by a single process is limited.
2) A data structure for storing a large amount of fd needs to be maintained, which makes it expensive for user space and kernel space to copy the structure.
3) the scan of fd is linear. After the sharp increase in fd, the efficiency of IO is low, because the fd is linearly scanned and traversed every call, so the increase of fd will cause slow traversal performance problems.
4) the timeout parameter of the select () function is also undefined when it returns. For portability, you need to reset the timeout parameter every time after the timeout and before entering the select next time.
Advantages:
1) select () is more portable and does not support poll () on some Unix systems.
2) select () provides better accuracy for timeout values: microseconds, while poll is milliseconds.
2 、 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. 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.
Disadvantages:
1) A large number of fd arrays are copied between the user mode and the kernel address space as a whole, whether such replication makes sense or not.
2) like select, when poll returns, you need to poll pollfd to get the ready descriptor
Advantages:
1) poll () does not require developers to calculate the size of the maximum file descriptor plus one.
2) poll () is faster than select when dealing with a large number of destination file descriptors.
3) it has no limit on the maximum number of connections because it is stored based on a linked list.
3 、 epoll
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. Another feature is that epoll uses the ready notification mode 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.
Advantages:
1) support a process to open a large number of destination socket descriptors (FD)
The most unbearable thing about select is that there is a certain limit to the FD opened by a process, which is set by FD_SETSIZE, and the default value is 1024amp 2048. It is obviously too small for IM servers that need to support tens of thousands of connections. At this point, you can choose to modify the macro and recompile the kernel. However, epoll does not have this restriction. The upper limit of FD it supports is the maximum number of files that can be opened. This number is generally much greater than 2048. For example, on a machine with 1GB memory, it is about 100000. The specific number can be seen by cat / proc/sys/fs/file-max. Generally speaking, this number has a lot to do with system memory.
2) IO efficiency does not decrease linearly with the increase of the number of FD.
Another fatal weakness of traditional select/poll is that when you have a large set of socket, but due to network delay, only part of the socket is "active" at any time, but select/poll will linearly scan all sets with each call, resulting in a linear decline in efficiency. But epoll doesn't have this problem, it only operates on "active" socket-because epoll is implemented according to the callback function above each fd in the kernel implementation. In that case, only the "active" socket will actively call the callback function, while other idle state socket will not, at this point, epoll implements a "pseudo" AIO, because the driving force is in the Linux kernel.
3) use mmap to accelerate messaging between the kernel and user space.
This actually involves the concrete implementation of epoll. Both select,poll and epoll require the kernel to notify user space of FD messages, so it is important to avoid unnecessary memory copies. At this point, epoll is implemented through the same memory block of kernel and user space mmap.
4. The comparison of the three.
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.