Class ElasticWait

java.lang.Object
io.perl.api.impl.ElasticWait

@NotThreadSafe public final class ElasticWait extends Object
Adapts the number of idle parks between wall-clock checks.

The first clock check is deliberately made after one park. Subsequent checks use the observed number of completed parks per millisecond instead of assuming that LockSupport.parkNanos(long) sleeps for exactly the requested duration. This makes the calibration independent of operating system timer granularity, scheduler behavior, CPU speed, and virtual versus platform thread execution.

This class is owned exclusively by the single PerL consumer thread.

  • Constructor Summary

    Constructors
    Constructor
    Description
    ElasticWait(int idleNS, int windowIntervalMS, int minIntervalMS)
    Constructor ElasticWait initialize all values.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Starts a new reporting window while retaining the measured park rate.
    void
    setElastic(long currentIntervalMS)
    Completes calibration for an expired window and starts the next window.
    void
    updateElastic(long elapsedIntervalMS)
    Updates calibration after a clock check within the current window.
    boolean
    Parks once and checks whether the next wall-clock sample is due.

    Methods inherited from class Object

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

    • ElasticWait

      public ElasticWait(int idleNS, int windowIntervalMS, int minIntervalMS)
      Constructor ElasticWait initialize all values.
      Parameters:
      idleNS - requested idle park duration in nanoseconds
      windowIntervalMS - reporting-window duration in milliseconds
      minIntervalMS - maximum bootstrap calibration interval in milliseconds
      Throws:
      IllegalArgumentException - if any argument is zero or negative
  • Method Details

    • reset

      public void reset()
      Starts a new reporting window while retaining the measured park rate.
    • waitAndCheck

      public boolean waitAndCheck()
      Parks once and checks whether the next wall-clock sample is due.
      Returns:
      true when the calibrated number of parks has completed
    • updateElastic

      public void updateElastic(long elapsedIntervalMS)
      Updates calibration after a clock check within the current window.

      The completed batch is always cleared. If the clock has not advanced far enough to measure a rate, the bootstrap batch grows exponentially up to the configured calibration interval. Otherwise the next clock check is scheduled for the remaining part of the reporting window.

      Parameters:
      elapsedIntervalMS - elapsed milliseconds in the current window
    • setElastic

      public void setElastic(long currentIntervalMS)
      Completes calibration for an expired window and starts the next window.
      Parameters:
      currentIntervalMS - elapsed milliseconds in the expired window