com.gilt.gfc.util
Used to rate-limit calls to a work function, e.g. that writes to a db.
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))
Frequency the system should strive to achieve on average. Not a guarantee
Frequency the system should strive to achieve on average.
Used to rate-limit calls to a work function, e.g. that writes to a db.
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))