Timer management: Nginx's red-black tree and Libevent heap

Source: Internet
Author: User

After the libevent has timed out,

The while loop once from the heap top del timer--until the most recently adjusted minimum heap top is not a timeout event (actually del event), but will later put this timeout's event into the active task list,

Wait for processing, the event is marked as timeout, and so on when the Actvie queue is processed by the application layer callback function to determine what to do with events marked as timeout.

Nginx processing Timeout, directly delete the red and black tree (in the event structure) of the RB node member, while calling the application layer has already passed the Add Timer registration good timeout handler function. The reason why the heap is not used

Because nodes are removed directly from the inside each time, instead of the top of the heap.

Key points, the heap is used, the deletion time is O (1), but to adjust the heap, Logn. The insertion time is basically LGN.

Using a red-black tree, deleting a node is 3 rotations, but finding the smallest node is logn. The insertion time is basically LGN.

Overall, it's pretty much the same. Http://blog.sina.com.cn/s/blog_56e6a0750101b0fo.html

Timer management: Nginx's red-black tree and Libevent heap

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.