byHashCode

public final static LogPerBucketingStrategy<Object> byHashCode(int maxBuckets)

A strategy which uses the hashCode() of a given key, modulo maxBuckets, for log aggregation.

This is a fallback strategy for cases where the set of possible values is not known in advance, or could be arbirarily large in unusual circumstances.

When using this method it is obviously important that the hashCode() method of the expected keys is well distributed, since duplicate hash codes, or hash codes congruent to maxBuckets will cause keys to be conflated.

The caller is responsible for deciding the number of unique log aggregation keys this strategy can return. This choice is a trade-off between memory usage and the risk of conflating keys when performing log aggregation. Each log site using this strategy will hold up to maxBuckets distinct versions of log site information to allow rate limiting and other stateful operations to be applied separately per bucket. The overall allocation cost depends on the type of rate limiting used alongside this method, but it scales linearly with maxBuckets.

It is recommended to keep the value of maxBuckets below 250, since this guarantees no additional allocations will occur when using this strategy, however the value chosen should be as small as practically possible for the typical expected number of unique keys.

To avoid unwanted allocation at log sites, users are strongly encouraged to assign the returned value to a static field, and pass that to any log statements which need it.