Class TokenBucketSampler

  • All Implemented Interfaces:
    Sampler

    @API(EXPERIMENTAL)
    public class TokenBucketSampler
    extends java.lang.Object
    implements Sampler
    A sampling engine which will pass a sample test according to a TokenBucket algorithm.

    A Token-bucket algorithm allows a constant average throughput, but allows some burstiness by building up tokens over periods of idleness. For more information, see Wikipedia. You can control the burstiness by configuring the maximum number of tokens to allow in the sampler, and the average rate by adjusting the refresh interval. Note, however, that the refresh interval is typically sensitive to the clock used in computing the interval--the refresh interval typically cannot be smaller than the resolution of the system clock used.

    • Constructor Summary

      Constructors 
      Constructor Description
      TokenBucketSampler​(int maxTokens, long refreshIntervalNanos, Clock clock)  
      TokenBucketSampler​(int maxTokens, long refreshInterval, java.util.concurrent.TimeUnit refreshTime, Clock clock)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canSample()
      Determine if a sample should be taken.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TokenBucketSampler

        public TokenBucketSampler​(int maxTokens,
                                  long refreshInterval,
                                  java.util.concurrent.TimeUnit refreshTime,
                                  Clock clock)
      • TokenBucketSampler

        public TokenBucketSampler​(int maxTokens,
                                  long refreshIntervalNanos,
                                  Clock clock)
    • Method Detail

      • canSample

        public boolean canSample()
        Determine if a sample should be taken.
        Specified by:
        canSample in interface Sampler
        Returns:
        true if a sample can be taken, false if it should be discarded.