Package flumotion :: Package component :: Package misc :: Package httpserver :: Module ratecontrol :: Class TokenBucketConsumer
[hide private]

Class TokenBucketConsumer

source code

extern.log.log.Loggable --+
                          |
                         TokenBucketConsumer

Use a token bucket to proxy between a producer (e.g. FileTransfer) and a consumer (TCP protocol, etc.), doing rate control.

The bucket has a rate and a maximum level, so a small burst can be permitted. The initial level can be set to a non-zero value, this is useful to implement burst-on-connect behaviour.

TODO: This almost certainly only works with producers that work like FileTransfer - i.e. they produce data directly in resumeProducing, and ignore pauseProducing. This is sufficient for our needs right now.

Instance Methods [hide private]
 
__init__(self, consumer, maxLevel, fillRate, fillLevel=0) source code
 
_dripAndTryWrite(self)
Re-fill our token bucket based on how long it has been since we last refilled it.
source code
 
_tryWrite(self) source code
 
_doUnregister(self) source code
 
_doFinish(self) source code
 
stopProducing(self) source code
 
pauseProducing(self) source code
 
resumeProducing(self) source code
 
write(self, data) source code
 
finish(self) source code
 
registerProducer(self, producer, streaming) source code
 
unregisterProducer(self) source code

Inherited from extern.log.log.Loggable: __providedBy__, debug, doLog, error, info, log, logFunction, logObjectName, warning, warningFailure, writeMarker

Class Variables [hide private]
  logCategory = 'token-bucket'
Implementors can provide a category to log their messages under.
  _dripInterval = 1.0

Inherited from extern.log.log.Loggable: __implemented__, __provides__

Method Details [hide private]

_dripAndTryWrite(self)

source code 

Re-fill our token bucket based on how long it has been since we last refilled it. Then attempt to write some data.