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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Clock | |
| private static final VarHandle | |
| private volatile LockFreeSlidingTimeWindowMetrics. | |
| private static final VarHandle | |
| private static final VarHandle | |
| private volatile LockFreeSlidingTimeWindowMetrics. | |
| private static final VarHandle | |
| private static final long | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public Snapshot | getSnapshot()
Implements io. Returns a snapshot. |
| 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. |
| private void |
| clock | back to summary |
|---|---|
| private final Clock clock | |
| HEAD | back to summary |
|---|---|
| private static final VarHandle HEAD | |
| headRef | back to summary |
|---|---|
| private volatile LockFreeSlidingTimeWindowMetrics. | |
| NEXT | back to summary |
|---|---|
| private static final VarHandle NEXT | |
| TAIL | back to summary |
|---|---|
| private static final VarHandle TAIL | |
| tailRef | back to summary |
|---|---|
| private volatile LockFreeSlidingTimeWindowMetrics. | |
| TIME_SLICE | back to summary |
|---|---|
| private static final VarHandle TIME_SLICE | |
| TIME_SLICE_DURATION_IN_NANOS | back to summary |
|---|---|
| private static final long TIME_SLICE_DURATION_IN_NANOS | |
| windowSize | back to summary |
|---|---|
| private final int windowSize | |
| LockFreeSlidingTimeWindowMetrics | back to summary |
|---|---|
| public LockFreeSlidingTimeWindowMetrics(int windowSize, Clock clock) | |
| LockFreeSlidingTimeWindowMetrics | back to summary |
|---|---|
| public LockFreeSlidingTimeWindowMetrics(int windowSize) | |
| advanceTimeSlice | back to summary |
|---|---|
| private void advanceTimeSlice() | |
| getSnapshot | back to summary |
|---|---|
| public Snapshot getSnapshot() Implements io. Doc from io. Returns a snapshot. | |
| record | back to summary |
|---|---|
| public Snapshot record(long duration, TimeUnit durationUnit, Metrics. Implements io. Doc from io. Records a call. | |
| updateWindow | back to summary |
|---|---|
| private void updateWindow(int second, long time) | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv volatile LockFreeSlidingTimeWindowMetrics. | |
| pack-priv volatile LockFreeSlidingTimeWindowMetrics. |
| Access | Constructor and Description |
|---|---|
| pack-priv | Node(LockFreeSlidingTimeWindowMetrics.
|
| next | back to summary |
|---|---|
| pack-priv volatile LockFreeSlidingTimeWindowMetrics. | |
| timeSlice | back to summary |
|---|---|
| pack-priv volatile LockFreeSlidingTimeWindowMetrics. | |
| Node | back to summary |
|---|---|
| pack-priv Node(LockFreeSlidingTimeWindowMetrics. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final boolean | |
| pack-priv final int | |
| pack-priv final PackedAggregation | |
| pack-priv final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public LockFreeSlidingTimeWindowMetrics. | |
| public void |
| processed | back to summary |
|---|---|
| pack-priv final boolean processed | |
| second | back to summary |
|---|---|
| pack-priv final int second | |
| stats | back to summary |
|---|---|
| pack-priv final PackedAggregation stats | |
| time | back to summary |
|---|---|
| pack-priv final long time | |
| TimeSlice | back to summary |
|---|---|
| public TimeSlice(int second, long time, PackedAggregation stats, boolean processed) | |
| copy | back to summary |
|---|---|
| public LockFreeSlidingTimeWindowMetrics. | |
| record | back to summary |
|---|---|
| public void record(Long duration, TimeUnit durationUnit, Metrics. | |