org.apache.lucene.store
Class RateLimiter

java.lang.Object
  extended by org.apache.lucene.store.RateLimiter

public class RateLimiter
extends Object

Simple class to rate limit IO. Typically it's shared across multiple IndexInputs or IndexOutputs (for example those involved all merging). Those IndexInputs and IndexOutputs would call pause(long) whenever they want to read bytes or write bytes.


Constructor Summary
RateLimiter(double mbPerSec)
          mbPerSec is the MB/sec max IO rate
 
Method Summary
 double getMbPerSec()
          The current mb per second rate limit.
 void pause(long bytes)
          Pauses, if necessary, to keep the instantaneous IO rate at or below the target.
 void setMbPerSec(double mbPerSec)
          Sets an updated mb per second rate limit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RateLimiter

public RateLimiter(double mbPerSec)
mbPerSec is the MB/sec max IO rate

Method Detail

setMbPerSec

public void setMbPerSec(double mbPerSec)
Sets an updated mb per second rate limit.


getMbPerSec

public double getMbPerSec()
The current mb per second rate limit.


pause

public void pause(long bytes)
Pauses, if necessary, to keep the instantaneous IO rate at or below the target. NOTE: multiple threads may safely use this, however the implementation is not perfectly thread safe but likely in practice this is harmless (just means in some rare cases the rate might exceed the target). It's best to call this with a biggish count, not one byte at a time.



Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.