com.gilt.gfc

util

package util

Visibility
  1. Public
  2. All

Type Members

  1. trait ExponentialBackoff extends Loggable

    To avoid tight loops around errors.

  2. class JRateLimiter extends ThreadSafeRateLimiter

    Java-friendly version of ThreadSafeRateLimiter.

  3. trait LimitCallback[T <: AnyRef] extends AnyRef

    Used by JRateLimiter in lieu of call-by-name from java.

  4. class RateLimiter extends AnyRef

    Used to rate limit writes to, say, mongo.

    Used to rate limit writes to, say, mongo. It's handy if the calling code can do bulk write operations through the limiter, which rate-limits how fast they happen.

    Note you can disable the rate limiter by setting the frequency to 0.

    The math is as follows (mod some conversions between seconds and nano-seconds):

    After n samples, we can computer Ri as the "immediate rate" like:

    Ri = (n-1) / (timestamp(n) - timestamp(0))

    which is essentially the 1/average interval.

    Given a target rate, Rt ("maxFreqHz"), we can compute it like:

    Rt = n / (S + (timestamp(n) - timestamp(0))

    S here is how long to sleep before we invoke the next operation. Solving for S:

    S = n / Rt - (timestamp(n) - timestamp(0))

  5. class SingletonCache[K] extends AnyRef

    For objects that need their lifecycle to be managed and can't be just throw-away.

    For objects that need their lifecycle to be managed and can't be just throw-away. E.g. for when ConcurrentHashMap.putIfAbsent(new Something()) may result in a Something instance that need to be closed if another thread's putIfAbsent was successful.

    In this case it's easier to not create unnecessary instances in the first place.

  6. class ThreadSafeRateLimiter extends RateLimiter

    Fairly heavy-handed thread safe version of the above.

    Fairly heavy-handed thread safe version of the above. There's not a lot of point to trying to avoid locking here, since the whole point of this thing is to block writes, so we might as well keep it simple.

Ungrouped