com.yammer.metrics.stats
Class ExponentiallyDecayingSample

java.lang.Object
  extended by com.yammer.metrics.stats.ExponentiallyDecayingSample
All Implemented Interfaces:
Sample

public class ExponentiallyDecayingSample
extends Object
implements Sample

An exponentially-decaying random sample of longs. Uses Cormode et al's forward-decaying priority reservoir sampling method to produce a statistically representative sample, exponentially biased towards newer entries.

See Also:
Cormode et al. Forward Decay: A Practical Time Decay Model for Streaming Systems. ICDE '09: Proceedings of the 2009 IEEE International Conference on Data Engineering (2009)

Constructor Summary
ExponentiallyDecayingSample(int reservoirSize, double alpha)
          Creates a new ExponentiallyDecayingSample.
 
Method Summary
 void clear()
          Clears all recorded values.
 void dump(File output)
          Writes the values of the sample to the given file.
 int size()
          Returns the number of values recorded.
 void update(long value)
          Adds a new recorded value to the sample.
 void update(long value, long timestamp)
          Adds an old value with a fixed timestamp to the sample.
 List<Long> values()
          Returns a copy of the sample's values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExponentiallyDecayingSample

public ExponentiallyDecayingSample(int reservoirSize,
                                   double alpha)
Creates a new ExponentiallyDecayingSample.

Parameters:
reservoirSize - the number of samples to keep in the sampling reservoir
alpha - the exponential decay factor; the higher this is, the more biased the sample will be towards newer values
Method Detail

clear

public void clear()
Description copied from interface: Sample
Clears all recorded values.

Specified by:
clear in interface Sample

size

public int size()
Description copied from interface: Sample
Returns the number of values recorded.

Specified by:
size in interface Sample
Returns:
the number of values recorded

update

public void update(long value)
Description copied from interface: Sample
Adds a new recorded value to the sample.

Specified by:
update in interface Sample
Parameters:
value - a new recorded value

update

public void update(long value,
                   long timestamp)
Adds an old value with a fixed timestamp to the sample.

Parameters:
value - the value to be added
timestamp - the epoch timestamp of value in seconds

values

public List<Long> values()
Description copied from interface: Sample
Returns a copy of the sample's values.

Specified by:
values in interface Sample
Returns:
a copy of the sample's values

dump

public void dump(File output)
          throws IOException
Description copied from interface: Sample
Writes the values of the sample to the given file.

Specified by:
dump in interface Sample
Parameters:
output - the file to which the values will be written
Throws:
IOException - if there is an error writing the values


Copyright © 2011. All Rights Reserved.