Class DataTransferThrottler

java.lang.Object
org.apache.hadoop.hdfs.util.DataTransferThrottler

public class DataTransferThrottler extends Object
a class to throttle the data transfers. This class is thread safe. It can be shared by multiple threads. The parameter bandwidthPerSec specifies the total bandwidth shared by threads.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataTransferThrottler(long bandwidthPerSec)
    Constructor
    DataTransferThrottler(long period, long bandwidthPerSec)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    void
    setBandwidth(long bytesPerSecond)
    Sets throttle bandwidth.
    void
    throttle(long numOfBytes)
    Given the numOfBytes sent/received since last time throttle was called, make the current thread sleep if I/O rate is too fast compared to the given bandwidth.
    void
    throttle(long numOfBytes, Canceler canceler)
    Given the numOfBytes sent/received since last time throttle was called, make the current thread sleep if I/O rate is too fast compared to the given bandwidth.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DataTransferThrottler

      public DataTransferThrottler(long bandwidthPerSec)
      Constructor
      Parameters:
      bandwidthPerSec - bandwidth allowed in bytes per second.
    • DataTransferThrottler

      public DataTransferThrottler(long period, long bandwidthPerSec)
      Constructor
      Parameters:
      period - in milliseconds. Bandwidth is enforced over this period.
      bandwidthPerSec - bandwidth allowed in bytes per second.
  • Method Details

    • getBandwidth

      public long getBandwidth()
      Returns:
      current throttle bandwidth in bytes per second.
    • setBandwidth

      public void setBandwidth(long bytesPerSecond)
      Sets throttle bandwidth. This takes affect latest by the end of current period.
    • throttle

      public void throttle(long numOfBytes)
      Given the numOfBytes sent/received since last time throttle was called, make the current thread sleep if I/O rate is too fast compared to the given bandwidth.
      Parameters:
      numOfBytes - number of bytes sent/received since last time throttle was called
    • throttle

      public void throttle(long numOfBytes, Canceler canceler)
      Given the numOfBytes sent/received since last time throttle was called, make the current thread sleep if I/O rate is too fast compared to the given bandwidth. Allows for optional external cancelation.
      Parameters:
      numOfBytes - number of bytes sent/received since last time throttle was called
      canceler - optional canceler to check for abort of throttle