• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
时间轮
 

时间轮

on

  • 821 views

 

Statistics

Views

Total Views
821
Views on SlideShare
209
Embed Views
612

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 612

http://www.tianjiaguo.com 612

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    时间轮 时间轮 Presentation Transcript

    • Hashed and Hierarchical Timing Wheels A paper by George Varghese and Tony Lauck
    • Motivation Timers are important for  Failure recovery, rate based flow control, scheduling algorithms, controlling packet lifetime in networks Timer maintenance high if  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 Routines in the model  Client Invoked :  START_TIMER(Interval, Request_ID, Expiry_Action)  STOP_TIMER(Request_ID)  Timer tick invoked :  PER_TICK_BOOKKEEPING  EXPIRY_PROCESSING Performance Measure  Space : Memory used by the data structures  Latency : Time required to begin and end any of the routines mentioned above
    • Currently Used Timer Schemes a a b b c c d d e e fCan maintain absolute expiry maintain absolute expiry timetime or the timer interval START_TIMER = O(n)START_TIMER = O(1) STOP_TIMER = O(1)STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1)PER_TICK_BOOKKEEPING = O(n)
    • Tree based timers a a b b c c d d Can degenerate to amaintain absolute expiry linear list in case of equaltime Interval timersSTART_TIMER = O(log(n)) START_TIMER = O(n)STOP_TIMER = O(1) STOP_TIMER = O(1)PER_TICK_BOOKKEEPING = O(1) PER_TICK_BOOKKEEPING = O(1)
    • Simple Timing Wheel  Keep a large timing wheel  A curser in the timing wheel moves one location every 0 1 time unit (just like a seconds 7 2 hand in the clock) 6  If the timer interval is within 3 a rotation from the current 5 4 curser position then put the timer in the corresponding location  Requires exponential amount START_TIMER = O(1) of memory STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1)
    • Hashed Timing Wheel # of rounds remaining  Say wheel has 8 ticks  Timer value = 17 2 4  Make 2 rounds of 0 1 wheel + 1 more tick 7  Schedule the timer in 2 the bucket “1” 6 3  Keep the # rounds with 1 2 5 4 the timer  At the expiry2 1 1 2 processing if the # rounds > 0 then reinsert the timer
    • Hashed Timing Wheel Sorted Lists in each bucket  The list in each bucket can be insertion sorted  Hence START_TIMER takes O(n) time in the worst case  If n < WheelSize then average O(1) Unsorted list in each bucket  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 < WheelSize then average O(1)
    • Hierarchical Timing Wheel 1 3 3 5 0 1 7 2 6 3 3 7 5 4 3 5 5 1 0 1 7Hours wheel 2 6 3 4 7 5 5 0 1 7 1 1 2 2 6 3 Minutes wheel 4 5 Seconds wheel
    • Hierarchical Timing Wheels START_TIMER = O(m) where m is the number of wheels  The bucket value on each wheel needs to be calculated STOP_TIMER = O(1) PER_TICK_BOOKKEEPING = O(1) on avg.
    • Comparison START_TIMER STOP_TIMER PER_TICK Straight Fwd O(1) O(1) O(n) Sequential O(n) O(1) O(1) List Tree Based O(log(n)) O(1) O(1) Simple Wheel O(1) O(1) O(1) High memory requirement Hashed O(n) worst case O(1) O(1)Wheel (sorted) O(1) avgHashed Wheel O(n) worst case O(1) O(1) (unsorted) O(1) avg Hierarchical O(m) O(1) O(1) Wheels