Implementation of several timer in ACE (timer Framework)

Source: Internet
Author: User
Tags hash

The ACE provides a rich timer function, and the following image shows the hierarchical relationship of the timer in the ACE.

In Aces, Class ace_timer_queue_t is an interface class that provides an abstraction of the public method of a Timer. ACE provides users with four kinds of timer implementations, the differences between the four implementations are mainly in the organization of the timer node data structure, and the use of the search algorithm. For four implementations, the performance of the ace_timer_heap_t is the highest, and they are analyzed separately below.

ace_timer_list_t: This implementation uses a doubly linked list to organize the Timer nodes. Finding the timer node is a linear scan, so its time complexity is O (n). The least performance implementation.

ace_timer_hash_t: This implementation uses a Hash table to organize the Timer nodes. How to calculate buckets, it takes a very simple way: the size of the% bucket will occur in the future at some point in time. Address conflicts use the chain address method. How to chain addresses, Ace takes the form of templates to make it flexible, ACE also provides an implementation that uses the heap to organize these conflicting nodes.

ace_timer_heap_t: This realization uses the small Gangalai organization Timer node, the efficiency is highest. Each insert and delete operation adjusts the heap so that it is always small Gan.

ace_timer_wheel_t: We can image it as a gear, the gear has a lot of teeth, each tooth and a doubly linked list connected. Inside the ace, he called the gear wheel, and the gear's teeth were called spoke. Each timer node is hashed into a spoke. The format of the timer ID is determined by the location of the spoke + how many timer nodes have been inserted into this spoke (spoke Timer node counter). Spoke can also be understood as the resolution of the timer, the size of the wheel and the resolution of the timer are specified by the user, and also provide default values. The formula for calculating the spoke value: (Number of bits in the future time-out >> resolution) & (total number of spoke-1). In fact, timer wheel is also a kind of Hash organization, compared to the realization of ace_timer_hash_t, the timer wheel can be defined by the user timer resolution, The timer node that hangs under the bucket is a node outside the range that the minimum resolution is not recognized. Flexibility from the angle of resolution. ace_timer_hash_t can customize the way the data is organized for the Timer nodes that are hanging under each bucket. Flexibility in the way data is organized.

The driver of the timer (the caller of expire in the timer) is the other frame in the ace, Reactor/proactor to do.

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.