Class HitRateMetric

  • All Implemented Interfaces:
    LongMetric, Metric

    public class HitRateMetric
    extends AbstractMetric
    implements LongMetric
    Accumulates approximate hit rate statistics. Calculates number of hits in last rateTimeInterval milliseconds. Algorithm is based on circular array of size hit counters, each is responsible for last corresponding time interval of rateTimeInterval/size milliseconds. Resulting number of hits is sum of all counters.

    Implementation is nonblocking and protected from hits loss. Maximum relative error is 1/size. 2^55 - 1 hits per interval can be accumulated without numeric overflow.

    • Field Detail

      • DFLT_SIZE

        public static final int DFLT_SIZE
        Default counters array size.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HitRateMetric

        public HitRateMetric​(String name,
                             @Nullable
                             @Nullable String desc,
                             long rateTimeInterval,
                             int size)
        Parameters:
        name - Name.
        desc - Description.
        rateTimeInterval - Rate time interval in milliseconds.
        size - Counters array size.
    • Method Detail

      • reset

        public void reset()
        Resets metric state.
        Specified by:
        reset in interface Metric
      • reset

        public void reset​(long rateTimeInterval)
        Resets metric with the new parametes.
        Parameters:
        rateTimeInterval - New rate time interval.
      • reset

        public void reset​(long rateTimeInterval,
                          int size)
        Resets metric with the new parameters.
        Parameters:
        rateTimeInterval - New rate time interval.
        size - New counters array size.
      • add

        public void add​(long x)
        Adds x to the metric.
        Parameters:
        x - Value to be added.
      • increment

        public void increment()
        Adds 1 to the metric.
      • value

        public long value()
        Specified by:
        value in interface LongMetric
        Returns:
        Value of the metric.
      • rateTimeInterval

        public long rateTimeInterval()
        Returns:
        Rate time interval in milliseconds.