public void schedule(final Runnable callback, final long workDurationNs) {
    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.
    if (currentWorkToIdleFactor == 0.0) {
      callback.run();
    } else {
      final long delay = Math.min(maxDelayNanos, (long) (workDurationNs * currentWorkToIdleFactor));

      // NOTE: we accumulate pending delay nanos here, but reduce the pending delay nanos after
      // the delay operation (if applicable), so they do not continue to grow.
      addToPendingNanos(delay);

      if (pendingNanos.get() < 0) {
        callback.run();
      } else {
        final long startTimeNs = clock.nanoTime();
        scheduledExecutorService.schedule(new Runnable() {
          @Override
          public void run() {
            final long actualDelay = clock.nanoTime() - startTimeNs;
            addToPendingNanos(-actualDelay);
            callback.run();
          }
        }, delay, TimeUnit.NANOSECONDS);
      }
    }
  }
This method may be used to throttle asynchronous processing by delaying the work completion callback.
<p>
Executes the given completion callback on the current thread. If throttling is enabled (the work factor
is less than 1.0) this method may optionally schedule the callback with a delay to satisfy the
requested work factor.

@param callback the callback to complete asynchronous work
@param workDurationNs the duration of asynchronous work in nanoseconds
samza-core/src/main/java/org/apache/samza/util/ThrottlingScheduler.java