voldemort.utils
Class EventThrottler

java.lang.Object
  extended by voldemort.utils.EventThrottler
Direct Known Subclasses:
DynamicEventThrottler

public class EventThrottler
extends java.lang.Object

A class to throttle Events to a certain rate This class takes a maximum rate in events/sec and a minimum interval in ms at which to check the rate. The rate is checked every time the interval ellapses, and if the events rate exceeds the maximum, the call will block long enough to equalize it. This is generalized IoThrottler as it existed before, you can use it to throttle on Bytes read/write,number of entries scanned etc.


Constructor Summary
EventThrottler(long ratesPerSecond)
           
EventThrottler(Time time, long ratePerSecond, long intervalMs)
           
 
Method Summary
 long getRate()
           
 void maybeThrottle(int eventsSeen)
          Sleeps if necessary to slow down the caller.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventThrottler

public EventThrottler(long ratesPerSecond)

EventThrottler

public EventThrottler(Time time,
                      long ratePerSecond,
                      long intervalMs)
Method Detail

getRate

public long getRate()

maybeThrottle

public void maybeThrottle(int eventsSeen)
Sleeps if necessary to slow down the caller.

Parameters:
eventsSeen - Number of events seen since last invocation. Basis for determining whether its necessary to sleep.


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu