Class TokenBucketSampler

java.lang.Object
com.apple.foundationdb.relational.util.TokenBucketSampler
All Implemented Interfaces:
Sampler

@API(EXPERIMENTAL) public class TokenBucketSampler extends 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 Details

    • TokenBucketSampler

      public TokenBucketSampler(int maxTokens, long refreshInterval, TimeUnit refreshTime, Clock clock)
    • TokenBucketSampler

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

    • 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.