Class LockFreeExponentiallyDecayingReservoir

java.lang.Object
io.dropwizard.metrics5.LockFreeExponentiallyDecayingReservoir
All Implemented Interfaces:
Reservoir

public final class LockFreeExponentiallyDecayingReservoir extends Object implements Reservoir
A lock-free 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.
Author:
Carter Kozak
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)

    LockFreeExponentiallyDecayingReservoir is based closely on the ExponentiallyDecayingReservoir, however it provides looser guarantees while completely avoiding locks.

    Looser guarantees:

    • Updates which occur concurrently with rescaling may be discarded if the orphaned state node is updated after rescale has replaced it. This condition has a greater probability as the rescale interval is reduced due to the increased frequency of rescaling. #rescaleThresholdNanos values below 30 seconds are not recommended.
    • Given a small rescale threshold, updates may attempt to rescale into a new bucket, but lose the CAS race and update into a newer bucket than expected. In these cases the measurement weight is reduced accordingly.
    • In the worst case, all concurrent threads updating the reservoir may attempt to rescale rather than a single thread holding an exclusive write lock. It's expected that the configuration is set such that rescaling is substantially less common than updating at peak load. Even so, when size is reasonably small it can be more efficient to rescale than to park and context switch.
  • Method Details

    • size

      public int size()
      Description copied from interface: Reservoir
      Returns the number of values recorded.
      Specified by:
      size in interface Reservoir
      Returns:
      the number of values recorded
    • update

      public void update(long value)
      Description copied from interface: Reservoir
      Adds a new recorded value to the reservoir.
      Specified by:
      update in interface Reservoir
      Parameters:
      value - a new recorded value
    • getSnapshot

      public Snapshot getSnapshot()
      Description copied from interface: Reservoir
      Returns a snapshot of the reservoir's values.
      Specified by:
      getSnapshot in interface Reservoir
      Returns:
      a snapshot of the reservoir's values
    • builder