@Override
  public long control(String opName, long size) throws InterruptedException {
    ActiveOperation operation = activeOperations.get(opName);
    operation.totalSize += size;
    long deltaSize = operation.totalSize - operation.lastControlSize;
    if (deltaSize < controlPerSize) {
      return 0;
    }
    long now = EnvironmentEdgeManager.currentTime();
    long minTimeAllowed = (long) (deltaSize / maxThroughputPerOperation * 1000); // ms
    long elapsedTime = now - operation.lastControlTime;
    operation.lastControlSize = operation.totalSize;
    if (elapsedTime >= minTimeAllowed) {
      operation.lastControlTime = EnvironmentEdgeManager.currentTime();
      return 0;
    }
    // too fast
    long sleepTime = minTimeAllowed - elapsedTime;
    if (LOG.isDebugEnabled()) {
      // do not log too much
      if (now - operation.lastLogTime > 5L * 1000) {
        LOG.debug("deltaSize: " + deltaSize + " bytes; elapseTime: " + elapsedTime + " ns");
        LOG.debug(opName + " sleep=" + sleepTime + "ms because current throughput is "
          + throughputDesc(deltaSize, elapsedTime) + ", max allowed is "
          + throughputDesc(maxThroughputPerOperation) + ", already slept "
          + operation.numberOfSleeps + " time(s) and total slept time is "
          + operation.totalSleepTime + " ms till now.");
        operation.lastLogTime = now;
      }
    }
    Thread.sleep(sleepTime);
    operation.numberOfSleeps++;
    operation.totalSleepTime += sleepTime;
    operation.lastControlTime = EnvironmentEdgeManager.currentTime();
    return sleepTime;
  }
Stores the information of one controlled compaction.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/PressureAwareThroughputController.java