Class FixedSizeSlidingWindowMetrics
java.lang.Object
io.github.resilience4j.core.metrics.FixedSizeSlidingWindowMetrics
- All Implemented Interfaces:
Metrics
A
Metrics implementation is backed by a sliding window that aggregates only the last
N calls.
The sliding window is implemented with a circular array of N measurements. If the time
window size is 10, the circular array has always 10 measurements.
The sliding window incrementally updates a total aggregation. The total aggregation is updated incrementally when a new call outcome is recorded. When the oldest measurement is evicted, the measurement is subtracted from the total aggregation. (Subtract-on-Evict)
The time to retrieve a Snapshot is constant 0(1), since the Snapshot is pre-aggregated and is independent of the window size. The space requirement (memory consumption) of this implementation should be O(n).
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.resilience4j.core.metrics.Metrics
Metrics.Outcome -
Field Summary
FieldsModifier and TypeFieldDescription(package private) intprivate final Measurement[]private final TotalAggregationprivate final int -
Constructor Summary
ConstructorsConstructorDescriptionFixedSizeSlidingWindowMetrics(int windowSize) Creates a newFixedSizeSlidingWindowMetricswith the given window size. -
Method Summary
Modifier and TypeMethodDescriptionprivate MeasurementReturns the head partial aggregation of the circular array.Returns a snapshot.(package private) voidMoves the headIndex to the next bucket.private Measurementrecord(long duration, TimeUnit durationUnit, Metrics.Outcome outcome) Records a call.
-
Field Details
-
windowSize
private final int windowSize -
totalAggregation
-
measurements
-
headIndex
int headIndex
-
-
Constructor Details
-
FixedSizeSlidingWindowMetrics
public FixedSizeSlidingWindowMetrics(int windowSize) Creates a newFixedSizeSlidingWindowMetricswith the given window size.- Parameters:
windowSize- the window size
-
-
Method Details
-
record
Description copied from interface:MetricsRecords a call. -
getSnapshot
Description copied from interface:MetricsReturns a snapshot.- Specified by:
getSnapshotin interfaceMetrics- Returns:
- a snapshot
-
moveWindowByOne
-
getLatestMeasurement
Returns the head partial aggregation of the circular array.- Returns:
- the head partial aggregation of the circular array
-
moveHeadIndexByOne
void moveHeadIndexByOne()Moves the headIndex to the next bucket.
-