latencyutils Documentation

repository·master·Indexed 19 days ago

https://github.com/latencyutils/latencyutils

A Java package for accurate latency statistics tracking. It provides the LatencyStats class to address coordinated omission, ensuring that system pauses (such as GC) do not result in falsely optimistic latency reports. It utilizes pluggable pause detectors and interval estimators to produce corrected histograms of operation durations.

Tokens
598
Snippets
1
Records
2
Agent score
17%

What's inside latencyutils

  1. How LatencyStats solves coordinated omission

    master

    Standard latency tracking (measuring time immediately before and after an operation) suffers from coordinated omission. This happens in two ways:

    1. Pause during operation: A single long latency is recorded, but it fails to account for the fact that other pending requests were also stalled by the same pause.
    2. Pause outside operation: If a pause occurs between operations, no long latency is recorded at all, even though the system was effectively unavailable for those requests.

    LatencyStats solves this by using pluggable pause detectors and interval estimators. These components work under the hood to transparently produce corrected histogram values that reflect the true latency behavior experienced by requests, including the impact of system pauses.

  2. Use LatencyStats to track operation latencies

    master

    The LatencyStats class is used to track recorded latencies in in-process scenarios. It is designed to handle 'coordinated omission'—a phenomenon where system pauses (like GC) skew latency statistics toward falsely-optimistic values. By using LatencyStats, you can record operation durations and later retrieve a corrected histogram that compensates for these pause effects using pluggable pause detectors and interval estimators.

    To use it, instantiate LatencyStats, record the duration of operations using recordLatency(long latency), and retrieve the results via getIntervalHistogram().

     LatencyStats myOpStats = new LatencyStats();
     ...
    
     // During normal operation, record all operation latencies into a LatencyStats instance:
     long startTime = System.nanoTime();
     // Perform operation:
     doMyOperation(...);
     // Record operation latency:
     myOpStats.recordLatency(System.nanoTime() - startTime);
     ...
    
     // Later, report on stats collected:
     Histogram intervalHistogram = myOpStats.getIntervalHistogram();
    
     intervalHistogram.outputPercentileDistribution(System.out, 1000000.0);