Class LockFreeSlidingTimeWindowMetrics
- All Implemented Interfaces:
Metrics
LockFreeFixedSizeSlidingWindowMetrics.
Each node of the sliding window represents the aggregated stats across 1 second (time slice). During a time slice, the algorithm is very simple consisting of a classical CAS-loop, in which the stats are copied, incremented, and a swap is attempted.
The complexity of the algorithm comes when the time slice is advanced. The algorithm needs to ensure that only one thread succeeds in advancing the time slice, i.e. a single time slice is advanced not multiple. This is achieved via an extra check when adding a new entry to the window, which guarantees that it is added only if it respects the time order, i.e. ith time slice is added only if it is preceded by the (i-1)th time slice.
It also needs to ensure that no stats updates are lost by updating a time slice in the past. This is accounted via a processed flag in the time slice, which marks that no further increments should happen for it.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface io.github.resilience4j.core.metrics.Metrics
Metrics.Outcome -
Constructor Summary
ConstructorsConstructorDescriptionLockFreeSlidingTimeWindowMetrics(int windowSize) LockFreeSlidingTimeWindowMetrics(int windowSize, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionReturns a snapshot.record(long duration, TimeUnit durationUnit, Metrics.Outcome outcome) Records a call.
-
Constructor Details
-
LockFreeSlidingTimeWindowMetrics
-
LockFreeSlidingTimeWindowMetrics
public LockFreeSlidingTimeWindowMetrics(int windowSize)
-
-
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
-