Class RateLimiter.SimpleRateLimiter

  • Enclosing class:
    RateLimiter

    public static class RateLimiter.SimpleRateLimiter
    extends RateLimiter
    Simple class to rate limit IO.
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleRateLimiter​(double mbPerSec)
      mbPerSec is the MB/sec max IO rate
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double getMbPerSec()
      The current mb per second rate limit.
      long 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

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleRateLimiter

        public SimpleRateLimiter​(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.
        Specified by:
        setMbPerSec in class RateLimiter
      • getMbPerSec

        public double getMbPerSec()
        The current mb per second rate limit.
        Specified by:
        getMbPerSec in class RateLimiter
      • pause

        public long 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.
        Specified by:
        pause in class RateLimiter
        Returns:
        the pause time in nano seconds