Package com.codahale.metrics
Class ExponentiallyDecayingReservoir
java.lang.Object
com.codahale.metrics.ExponentiallyDecayingReservoir
- All Implemented Interfaces:
Reservoir
An exponentially-decaying random reservoir of
longs. Uses Cormode et al's
forward-decaying priority reservoir sampling method to produce a statistically representative
sampling reservoir, exponentially biased towards newer entries.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final doubleprivate final Clockprivate final AtomicLongprivate static final doubleprivate static final intprivate final ReentrantReadWriteLockprivate final AtomicLongprivate static final longprivate final intprivate longprivate final ConcurrentSkipListMap<Double, Long> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newExponentiallyDecayingReservoirof 1028 elements, which offers a 99.9% confidence level with a 5% margin of error assuming a normal distribution, and an alpha factor of 0.015, which heavily biases the reservoir to the past 5 minutes of measurements.ExponentiallyDecayingReservoir(int size, double alpha) Creates a newExponentiallyDecayingReservoir.ExponentiallyDecayingReservoir(int size, double alpha, Clock clock) Creates a newExponentiallyDecayingReservoir. -
Method Summary
Modifier and TypeMethodDescriptionprivate longReturns a snapshot of the reservoir's values.private voidprivate voidprivate voidrescale(long now, long next) private voidintsize()Returns the number of values recorded.private voidprivate voidvoidupdate(long value) Adds a new recorded value to the reservoir.voidupdate(long value, long timestamp) Adds an old value with a fixed timestamp to the reservoir.private doubleweight(long t)
-
Field Details
-
DEFAULT_SIZE
private static final int DEFAULT_SIZE- See Also:
-
DEFAULT_ALPHA
private static final double DEFAULT_ALPHA- See Also:
-
RESCALE_THRESHOLD
private static final long RESCALE_THRESHOLD -
values
-
lock
-
alpha
private final double alpha -
size
private final int size -
count
-
startTime
private volatile long startTime -
nextScaleTime
-
clock
-
-
Constructor Details
-
ExponentiallyDecayingReservoir
public ExponentiallyDecayingReservoir()Creates a newExponentiallyDecayingReservoirof 1028 elements, which offers a 99.9% confidence level with a 5% margin of error assuming a normal distribution, and an alpha factor of 0.015, which heavily biases the reservoir to the past 5 minutes of measurements. -
ExponentiallyDecayingReservoir
public ExponentiallyDecayingReservoir(int size, double alpha) Creates a newExponentiallyDecayingReservoir.- Parameters:
size- the number of samples to keep in the sampling reservoiralpha- the exponential decay factor; the higher this is, the more biased the reservoir will be towards newer values
-
ExponentiallyDecayingReservoir
Creates a newExponentiallyDecayingReservoir.- Parameters:
size- the number of samples to keep in the sampling reservoiralpha- the exponential decay factor; the higher this is, the more biased the reservoir will be towards newer values
-
-
Method Details
-
size
public int size()Description copied from interface:ReservoirReturns the number of values recorded. -
update
public void update(long value) Description copied from interface:ReservoirAdds a new recorded value to the reservoir. -
update
public void update(long value, long timestamp) Adds an old value with a fixed timestamp to the reservoir.- Parameters:
value- the value to be addedtimestamp- the epoch timestamp ofvaluein seconds
-
rescaleIfNeeded
private void rescaleIfNeeded() -
getSnapshot
Description copied from interface:ReservoirReturns a snapshot of the reservoir's values.- Specified by:
getSnapshotin interfaceReservoir- Returns:
- a snapshot of the reservoir's values
-
currentTimeInSeconds
private long currentTimeInSeconds() -
weight
private double weight(long t) -
rescale
private void rescale(long now, long next) -
unlockForRescale
private void unlockForRescale() -
lockForRescale
private void lockForRescale() -
lockForRegularUsage
private void lockForRegularUsage() -
unlockForRegularUsage
private void unlockForRegularUsage()
-