Hashed and Hierarchical Timing Wheels A paper by
Hashed and Hierarchical Timing Wheels A paper by George Varghese and Tony Lauck
Motivation n Timers are important for n n Timer maintenance high if n n Failure recovery, rate based flow control, scheduling algorithms, controlling packet lifetime in networks Processor interrupted every clock tick Fine granularity timers are used # outstanding timers is high Efficient timer algorithms are required to reduce the overall interrupt overhead
Model & Performance Measure n Routines in the model n Client Invoked : n n n Timer tick invoked : n n n START_TIMER(Interval, Request_ID, Expiry_Action) STOP_TIMER(Request_ID) PER_TICK_BOOKKEEPING EXPIRY_PROCESSING Performance Measure n n Space : Memory used by the data structures Latency : Time required to begin and end any of the routines mentioned above
Simple Timer Schemes (1 & 2) a a b c d e Scheme 1: Can maintain absolute expiry time or the timer interval START_TIMER = O(1) STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(n) b c d e f Scheme 2: maintain absolute expiry time START_TIMER = O(n) STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1)
Tree based timers (3) a a b b c c d d Scheme 3: maintain absolute expiry time START_TIMER = O(log(n)) STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1) Can degenerate to a linear list in case of equal Interval timers START_TIMER = O(n) STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1)
Simple Timing Wheel (4) n n n 0 1 7 2 6 3 5 4 START_TIMER = O(1) STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1) n Scheme 4 Keep a large timing wheel A cursor in the timing wheel moves one location every time unit (just like a seconds hand in the clock) If the timer interval is within a rotation from the current curser position then put the timer in the corresponding location
Hashed Timing Wheel (5+6) # of rounds remaining n n 2 0 2 1 2 6 3 1 n 1 7 5 4 4 2 n 1 2 n n Say wheel has 8 ticks Timer value = 17 Make 2 rounds of wheel + 1 more tick Schedule the timer in the bucket “ 1” Keep the # rounds with the timer At the expiry processing if the # rounds > 0 then reinsert the timer
Hashed Timing Wheel n Scheme 5: Sorted Lists in each bucket n n The list in each bucket can be insertion sorted Hence START_TIMER takes O(n) time in the worst case If n < Wheel. Size then average O(1) Scheme 6: Unsorted list in each bucket n n n List can be kept unsorted to avoid worst case O(n) latency for START_TIMER However worst case PER_TICK_BOOKKEEPING = O(n) Again, if n < Wheel. Size then average O(1)
Hierarchical Timing Wheel 1 3 0 7 3 5 1 2 6 3 5 4 3 7 3 5 1 0 7 Hours wheel 1 2 6 3 5 1 Minutes wheel 4 2 7 5 0 7 1 2 6 3 5 4 Seconds wheel
Hierarchical Timing Wheels n n Scheme 6, extension 2 START_TIMER = O(m) where m is the number of wheels n n n The bucket value on each wheel needs to be calculated STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1) on avg.
Comparison Scheme Name Start Stop Per-Tick 1 Straightforward O(1) O(N) 2 Ordered List O(N) O(1) 3 Tree O(log(N)) O(1) 4 Simple Wheel* O(1) 5 Hashed Wheel (sorted) O(N) WC, O(1) Avg O(1) 6 Hashed Wheel (unsorted) O(1) O(N) WC, O(1) Avg 6 -ext 2 Hierarchical* O(m) O(1) *Overflow list
- Slides: 11