Class ElasticWait
java.lang.Object
io.perl.api.impl.ElasticWait
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
ConstructorsConstructorDescriptionElasticWait(int idleNS, int windowIntervalMS, int minIntervalMS) Constructor ElasticWait initialize all values. -
Method Summary
Modifier and TypeMethodDescriptionvoidreset()Starts a new reporting window while retaining the measured park rate.voidsetElastic(long currentIntervalMS) Completes calibration for an expired window and starts the next window.voidupdateElastic(long elapsedIntervalMS) Updates calibration after a clock check within the current window.booleanParks once and checks whether the next wall-clock sample is due.
-
Constructor Details
-
ElasticWait
public ElasticWait(int idleNS, int windowIntervalMS, int minIntervalMS) Constructor ElasticWait initialize all values.- Parameters:
idleNS- requested idle park duration in nanosecondswindowIntervalMS- reporting-window duration in millisecondsminIntervalMS- 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
-