Class SimRate
- All Implemented Interfaces:
RateLimiter,NBComponent,NBComponentAdvisors,NBComponentEvents,NBComponentMetrics,NBComponentProps,NBComponentServices,NBComponentTimeline,NBProviderSearch,NBTokenWords,NBLabeledElement,AutoCloseable,Thread.UncaughtExceptionHandler
Invariants
- When filler is defined, the pool is being replenished, and the rate limiter is active.
- Any changes to filler state or filler actions must be guarded by the filler lock.
- Summary stats are accumulated when the filler is stopped.
- State is initialized when the filler is started.
In order to use Semaphore, the canonical implementation which is designed to work
best with virtual threads, we have to scale time so that the token bucket will fit within 2^31.
To make this work across a range of rates from very slow to very fast, the resolution of time tracking has
to be set according to the rate specified.
Explanation:
- The time divisor in the rate is properly established as per interval. Conventionally, a rate specified as "46Kops" is taken to mean "46Kops/s" or per second.
- The time which passes on the wall clock is the inverse of this, or in the example above, 1/46000 of a second (21739 nanoseconds ideally).
- At lower rates, like 0.01 ops/s, a number of seconds must pass with time accumulating into the token pool. For 0.01/s, the number of nanoseconds representing a single op is 100_000_000_000, or more than 46 times the value which is representable in a 32 bit semaphore.
- By scaling the time unit, 0.01 ops/s can be represented as microseconds without losing significant timing resolution with respect to the rate.
- This scale factor works well to accommodate burst ratios up to 100%
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface io.nosqlbench.nb.api.labels.NBLabeledElement
NBLabeledElement.BasicLabeledElement -
Field Summary
Fields inherited from class io.nosqlbench.nb.api.components.core.NBBaseComponent
bufferOrphanedMetrics, closed_ns, error, errored_ns, labels, metricsBuffer, parent, started_epoch_ms, started_ns, state, teardown_nsFields inherited from interface io.nosqlbench.nb.api.components.core.NBComponent
EMPTY_COMPONENTFields inherited from interface io.nosqlbench.nb.api.components.core.NBComponentProps
HDRDIGITS, SUMMARYFields inherited from interface io.nosqlbench.nb.api.labels.NBLabeledElement
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionSimRate(NBComponent parent, SimRateSpec spec) SimRate(NBComponent parent, SimRateSpec spec, NBLabels extraLabels) -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyRateSpec(SimRateSpec updatingSimRateSpec) Modify the rate of a running rate limiter.longblock()Block until it is time for the next operation, according to the nanoseconds per op as set byRateLimiter.applyRateSpec(SimRateSpec)getSpec()Get the rate spec that this rate limiter was created from.longReturn the system nanoseconds at the time when the last rate change was made active by a starting or restarting rate spec.Return the total number of nanoseconds behind schedule that this rate limiter is, including the full history across all rates.Return the total number of nanoseconds behind schedule that this rate limiter is, but only since the last time the rate spec has changed.doublevoidinitPools(SimRateSpec simRateSpec) longrefill()toString()voiduncaughtException(Thread t, Throwable e) <U,V> Function <U, V> Methods inherited from class io.nosqlbench.nb.api.components.core.NBBaseComponent
addAdvisor, addMetricsCloseable, attachChild, beforeDetach, close, create, detachChild, find, findParentService, getAdvisors, getChildren, getComponentOnlyLabels, getComponentProp, getComponentState, getLabels, getNanosSinceStart, getParent, getTokens, nanosof_close, nanosof_error, nanosof_start, nanosof_teardown, onError, onEvent, reportExecutionMetric, setComponentProp, started_epoch_ms, teardownMethods inherited from class io.nosqlbench.nb.api.components.core.NBBaseComponentMetrics
addComponentMetric, addListener, findComponentMetrics, findComponentMetrics, getComponentMetric, getComponentMetrics, removeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.nosqlbench.nb.api.components.core.NBComponentAdvisors
getAdvisorResultsMethods inherited from interface io.nosqlbench.nb.api.components.core.NBComponentMetrics
addComponentMetric, findComponentMetrics, findComponentMetrics, findOneComponentMetric, findOneComponentMetric, getComponentMetric, getComponentMetricsMethods inherited from interface io.nosqlbench.nb.api.labels.NBLabeledElement
description
-
Constructor Details
-
SimRate
-
SimRate
-
-
Method Details
-
refill
public long refill() -
applyRateSpec
Description copied from interface:RateLimiterModify the rate of a running rate limiter.- Specified by:
applyRateSpecin interfaceRateLimiter- Parameters:
updatingSimRateSpec- The rate and burstRatio specification
-
getWaitTimeDuration
Description copied from interface:RateLimiterReturn the total number of nanoseconds behind schedule that this rate limiter is, but only since the last time the rate spec has changed. When the rate is changed, this value is check-pointed to an accumulator and also included in any subsequent measurement.- Specified by:
getWaitTimeDurationin interfaceRateLimiter- Returns:
- nanoseconds behind schedule since the rate limiter was started
-
getWaitTimeSeconds
public double getWaitTimeSeconds()- Specified by:
getWaitTimeSecondsin interfaceRateLimiter
-
initPools
-
block
public long block()Description copied from interface:RateLimiterBlock until it is time for the next operation, according to the nanoseconds per op as set by
RateLimiter.applyRateSpec(SimRateSpec)- Specified by:
blockin interfaceRateLimiter- Returns:
- the waittime as nanos behind schedule when this op returns.
The returned value is required to be greater than or equal to zero.
Note that accuracy of the returned value is limited by timing precision and calling overhead of the real time clock. It will not generally be better than microseconds. Also, some rate limiting algorithms are unable to efficiently track per-op waittime at speed due to bulk allocation mechanisms necessary to support higher rates.
-
uncaughtException
- Specified by:
uncaughtExceptionin interfaceThread.UncaughtExceptionHandler
-
getSpec
Description copied from interface:RateLimiterGet the rate spec that this rate limiter was created from.- Specified by:
getSpecin interfaceRateLimiter- Returns:
- a RateSpec that describes this rate limiter
-
toString
- Overrides:
toStringin classNBBaseComponent
-
wrap
-
getTotalWaitTimeDuration
Description copied from interface:RateLimiterReturn the total number of nanoseconds behind schedule that this rate limiter is, including the full history across all rates. When the rate is changed, this value is check-pointed to an accumulator and also included in any subsequent measurement.- Specified by:
getTotalWaitTimeDurationin interfaceRateLimiter- Returns:
- nanoseconds behind schedule since the rate limiter was started
-
getStartTime
public long getStartTime()Description copied from interface:RateLimiterReturn the system nanoseconds at the time when the last rate change was made active by a starting or restarting rate spec.- Specified by:
getStartTimein interfaceRateLimiter- Returns:
- long nanoseconds
-