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).
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| private final ReentrantLock | |
| private final Measurement[] | |
| private final TotalAggregation | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public | FixedSizeSlidingWindowMetrics(int
the window size windowSize)Creates a new |
| Modifier and Type | Method and Description |
|---|---|
| private Measurement | Returns: the head partial aggregation of the circular arrayReturns the head partial aggregation of the circular array. |
| public Snapshot | getSnapshot()
Implements io. Returns a snapshot. |
| pack-priv void | |
| private Measurement | |
| public Snapshot | record(long
the duration of the call duration, TimeUnit the time unit of the duration durationUnit, Metrics.the outcome of the call outcomeImplements io. Records a call. |
| headIndex | back to summary |
|---|---|
| pack-priv int headIndex | |
| lock | back to summary |
|---|---|
| private final ReentrantLock lock | |
| measurements | back to summary |
|---|---|
| private final Measurement[] measurements | |
| totalAggregation | back to summary |
|---|---|
| private final TotalAggregation totalAggregation | |
| windowSize | back to summary |
|---|---|
| private final int windowSize | |
| FixedSizeSlidingWindowMetrics | back to summary |
|---|---|
| public FixedSizeSlidingWindowMetrics(int windowSize) Creates a new
| |
| getLatestMeasurement | back to summary |
|---|---|
| private Measurement getLatestMeasurement() Returns the head partial aggregation of the circular array.
| |
| getSnapshot | back to summary |
|---|---|
| public Snapshot getSnapshot() Implements io. Doc from io. Returns a snapshot.
| |
| moveHeadIndexByOne | back to summary |
|---|---|
| pack-priv void moveHeadIndexByOne() Moves the headIndex to the next bucket. | |
| moveWindowByOne | back to summary |
|---|---|
| private Measurement moveWindowByOne() | |
| record | back to summary |
|---|---|
| public Snapshot record(long duration, TimeUnit durationUnit, Metrics. Implements io. Doc from io. Records a call. | |