public void execute(Runnable command) {
    final double currentWorkToIdleFactor = workToIdleFactor;

    // If we're not throttling, do not get clock time, etc. This substantially reduces the overhead
    // per invocation of this feature (by ~75%).
    if (currentWorkToIdleFactor == 0.0) {
      command.run();
    } else {
      final long startWorkNanos = clock.nanoTime();
      command.run();
      final long workNanos = clock.nanoTime() - startWorkNanos;

      // NOTE: we accumulate pending delay nanos here, but we later update the pending nanos during
      // the sleep operation (if applicable), so they do not continue to grow. We also clamp the
      // maximum sleep time to prevent excessively large sleeps between executions.
      pendingNanos = Math.min(maxDelayNanos,
          MathUtil.clampAdd(pendingNanos, (long) (workNanos * currentWorkToIdleFactor)));
      if (pendingNanos > 0) {
        try {
          pendingNanos = sleep(pendingNanos);
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
        }
      }
    }
  }
Executes the given command on the current thread. If throttling is enabled (the work factor
is less than 1.0) this command may optionally insert a delay before returning to satisfy the
requested work factor.
<p>
This method will not operate correctly if used by more than one thread.

@param command the work to execute
samza-core/src/main/java/org/apache/samza/util/ThrottlingExecutor.java