Class SlidingTimeWindowMetrics
- java.lang.Object
-
- io.github.resilience4j.core.metrics.SlidingTimeWindowMetrics
-
- All Implemented Interfaces:
Metrics
public class SlidingTimeWindowMetrics extends java.lang.Object implements Metrics
AMetricsimplementation is backed by a sliding time window that aggregates only the calls made in the lastNseconds.The sliding time window is implemented with a circular array of
Npartial aggregations (buckets). If the time window size is 10 seconds, the circular array has always 10 partial aggregations (buckets). Every bucket aggregates the outcome of all calls which happen in a certain epoch second. (Partial aggregation) The head bucket of the circular array stores the call outcomes of the current epoch second. The other partial aggregations store the call outcomes of the previousN-1epoch seconds.The sliding window does not store call outcomes (tuples) individually, but incrementally updates partial aggregations (bucket) and a total aggregation. The total total aggregation is updated incrementally when a new call outcome is recorded. When the oldest bucket is evicted, the partial total aggregation of that bucket 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 time window size. The space requirement (memory consumption) of this implementation should be nearly constant O(n), since the call outcomes (tuples) are not stored individually. Only
Npartial aggregations and 1 total total aggregation are created.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.github.resilience4j.core.metrics.Metrics
Metrics.Outcome
-
-
Constructor Summary
Constructors Constructor Description SlidingTimeWindowMetrics(int timeWindowSizeInSeconds, java.time.Clock clock)Creates a newSlidingTimeWindowMetricswith the given clock and window of time.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SnapshotgetSnapshot()Returns a snapshot.Snapshotrecord(long duration, java.util.concurrent.TimeUnit durationUnit, Metrics.Outcome outcome)Records a call.
-
-
-
Constructor Detail
-
SlidingTimeWindowMetrics
public SlidingTimeWindowMetrics(int timeWindowSizeInSeconds, java.time.Clock clock)Creates a newSlidingTimeWindowMetricswith the given clock and window of time.- Parameters:
timeWindowSizeInSeconds- the window time size in secondsclock- theClockto use
-
-
Method Detail
-
record
public Snapshot record(long duration, java.util.concurrent.TimeUnit durationUnit, Metrics.Outcome outcome)
Description copied from interface:MetricsRecords a call.
-
getSnapshot
public Snapshot getSnapshot()
Description copied from interface:MetricsReturns a snapshot.- Specified by:
getSnapshotin interfaceMetrics- Returns:
- a snapshot
-
-