[Click] adding TokenBucket

Cliff Frey cliff at meraki.com
Wed Jan 5 01:50:32 EST 2011


Eddie and I worked on a new TokenBucket data structure that is good for
implementing rate-limited operations (like RatedUnqueue).  I'm hoping to
push this to mainline soon, but wanted to solicit feedback from the list
first.

The commits have the details.  I'm mostly curious if anyone objects to the
behavioral change to the Rated* elements having a 1 second burst.

https://github.com/clifffrey/click/commit/96dfb6a571dcb6911bb0f2cc4f933890e4801906
https://github.com/clifffrey/click/commit/709f87e0dd424462b48d581f94445832a85f87f4

commit 709f87e0dd424462b48d581f94445832a85f87f4
Author: Cliff Frey <cliff at meraki.com>
Date:   Tue Jan 4 22:13:06 2011

    TokenBucket: a class useful for implementing rates

    Most of this is actually work by Eddie Kohler.

    This work was sponsored by Meraki, Inc.


commit 96dfb6a571dcb6911bb0f2cc4f933890e4801906
Author: Cliff Frey <cliff at meraki.com>
Date:   Tue Jan 4 22:22:53 2011

    Change (BW)Rated elements to use TokenBuckets instead of GapRate

    The biggest functional change here (by far) is that these elements now
    have a 1 second burst.  This means that a BWRatedUnqueue element
    configured at 1MBps will unqueue 1MB as quickly as it possibly can
    (because the TokenBucket will start out with 1MB worth of tokens), and
    after that, it will average 1MBps.  However, the elements should
    deliver much more reliable throughput, especially in cases where there
    is some bursty CPU behavior.

    The other change is that these elements all now include timers which
    they are willing to use, so they should not ever end up pegging the
    CPU.

    This also greatly improves performance.  I believe that this is
    because of TokenBucket's relative efficiency to GapRate.
      cat myconfig
        InfiniteSource(LIMIT 4000000, TIMESTAMP false, STOP true)
        -> Queue(CAPACITY 100)
        -> RatedUnqueue(4000000000)
        -> Discard
      time ./userlevel/click myconfig
        real                  0m6.319s
        user                  0m3.212s
        sys                   0m3.088s
      time ./userlevel/click myconfig
        real                  0m1.729s
        user                  0m1.200s
        sys                   0m0.520s


More information about the click mailing list