Class SbkRateController

java.lang.Object
io.sbk.api.impl.SbkRateController
All Implemented Interfaces:
RateController

public final class SbkRateController extends Object implements RateController
Simple rate controller used by SBK to pace operations to a target records-per-second value.

The controller computes an average inter-record sleep time in nanoseconds and accumulates fractional sleep time to decide when to perform an actual Thread.sleep with millisecond+nanosecond precision. This avoids sleeping on every operation while preserving long-term throughput accuracy.

Notes:

  • If recordsPerSec is zero or negative the controller is inactive.
  • Sleep durations smaller than MIN_SLEEP_NS are accumulated and coalesced before a blocking sleep is issued to avoid excessive context switches.
  • Constructor Details

    • SbkRateController

      public SbkRateController()
  • Method Details

    • start

      public void start(int recordsPerSec)
      Start the Rate Controller.
      Specified by:
      start in interface RateController
      Parameters:
      recordsPerSec - Records Per Second.
    • control

      public void control(long events, double elapsedSec)
      Blocks for small amounts of time to achieve target Throughput/events per sec.
      Specified by:
      control in interface RateController
      Parameters:
      events - current cumulative events
      elapsedSec - Elapsed seconds