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 > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "what is the difference between select/poll/epoll in Icano multiplexing", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the difference between select/poll/epoll in Icano multiplexing".
Select,poll,epoll is the mechanism of operating system to realize IO multiplexing. We know that Imax O multiplexing uses a mechanism to monitor multiple descriptors, and once a descriptor is ready (usually read-ready or write-ready), it can tell the program to read and write accordingly. So what's the difference between these three mechanisms?
1. Support the maximum number of connections a process can open
Select: the maximum number of connections that can be opened by a single process is defined by the FD_SETSIZE macro, which is the size of 32 integers (on 32-bit machines, the size is 32-bit 32, and FD_SETSIZE is 32-bit 64 on the same 64-bit machine). Of course, we can modify it and recompile the kernel, but performance may be affected.
Poll:poll is essentially no different from select, but it has no limit on the maximum number of connections because it is stored based on linked lists.
Epoll: although there is an upper limit on the number of connections, it is very large. About 100000 connections can be opened on machines with 1 GB of memory, and about 200000 connections can be opened on machines with 2 GB of memory.
2. The problem of IO efficiency caused by the sharp increase of FD.
Select: because the connection is linearly traversed with each call, the increase of FD will cause a "linear degradation performance problem" with slow traversal speed.
Poll: ditto.
Epoll because the implementation in the epoll kernel is implemented according to the callback function on each fd, only active socket will actively call callback, so when there is less active socket, there is no linear degradation performance problem of using epoll, but when all socket are active, there may be performance problems.
3. Message delivery mode
Select: the kernel needs to pass messages to user space, as well as kernel copy actions.
Poll: ditto.
Epoll:epoll is implemented by sharing a piece of memory between the kernel and user space.
Summary:
To sum up, the choice of select,poll,epoll should be based on the specific occasions of use and the characteristics of the three ways.
1. On the surface, epoll has the best performance, but when the number of connections is small and the connections are very active, the performance of select and poll may be better than epoll. After all, the notification mechanism of epoll requires a lot of function callbacks.
Select is inefficient because it needs to be polled every time. But inefficiency is also relative, depending on the situation, can also be improved through good design.
Additional knowledge points:
Level_triggered (horizontal trigger): when a read-write event occurs on the monitored file descriptor, epoll_wait () notifies the handler to read and write. If you don't read and write all the data at once (for example, the read-write buffer is too small), the next time you call epoll_wait (), it will tell you to continue reading and writing on the file descriptor that you haven't finished reading and writing. Of course, if you don't read and write all the time, it will keep telling you! If there are a large number of ready file descriptors in the system that you do not need to read or write, and they return every time, this will greatly reduce the efficiency of the processor in retrieving the ready file descriptors that you care about!
Edge_triggered (Edge trigger): when a read-write event occurs on the monitored file descriptor, epoll_wait () notifies the handler to read and write. If you don't read and write all the data this time (for example, the read-write buffer is too small), it will not notify you the next time it calls epoll_wait (), that is, it will notify you only once until the second read-write event appears on the file descriptor! This mode is more efficient than horizontal trigger, and the system will not be filled with a large number of ready file descriptors that you don't care about!
Both select () and poll () models are horizontal trigger mode, signal-driven IO is edge trigger mode, epoll () model supports both horizontal trigger and edge trigger, and the default is horizontal trigger.
These are all the contents of this article entitled "what is the difference between select/poll/epoll in iPandar O Multiplexing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.