当前位置:网站首页>Why is epoll efficient?

Why is epoll efficient?

2022-06-21 13:59:00 Do not deceive the dark room__

Epoll The bottom implementation of is shown in the figure above :( understand )

  • ( Red and black trees , Is a special binary tree ,Epoll How can I monitor many ? First create the root node of the tree , Each root node is a fd Store in the form of a structure ( The node contains some attributes , contain callback function ), For a tree, you can attach nodes at will .
  • Linked list , When a file descriptor generates an event , Automatically called callback function , Through the callback callback Function to find the event corresponding to the linked list ( Read time or write events ), The linked list is an event linked list .

epoll Why efficient ?

1.select and poll The monitored files need to be copied and transferred between the operating system and the kernel layer , Each poll needs to be copied from the user layer to the kernel layer , Efficiency is very low , and epoll The kernel layer and the user layer share memory , The monitor event descriptor does not exist in the kernel layer nor in the application layer , The kernel layer monitors directly from the shared space , Greatly improved efficiency

2.select Polling mechanism used , Polling , That is, the event occurrence query will be performed for each monitored event descriptor , Low efficiency , and epoll Use the event notification mechanism , namely

The event will be notified , Instead of polling , Greatly improved efficiency .

原网站

版权声明
本文为[Do not deceive the dark room__]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221430315062.html