BatchedThrottle is a {@link SleepThrottle} that uses batching to achieve much higher throttling rates than a sleepthrottle can. Sleep throttle has difficulties once the rate gets above a few hundred hertz, because the JVM cannot generate timed pauses that are that short. BatchedThrottle gets around this by only inserting pauses once every so many calls to the {@link #throttle()} method, and using a sleep throttle run at a lower rate. The rate for the sleepthrottle is chosen so that it remains under 100hz. The final throttling rate of this throttle is equal to the batch size times the rate of the underlying sleep throttle.
The batching calculation involves taking the log to the base 100 of the desired rate and rounding this to an integer. The batch size is always an exact power of 100 because of the rounding. The rate for an underlying sleep throttle is then chosen appropriately.
In practice, the accuracy of a BacthedThrottle skews off but can sometimes even be reasonable up to ten thousand hertz compared with 100 Hz for a {@link SleepThrottle}.
CRC Card Responsibilities | Collaborations |
---|
Accept throttling rate in operations per second. |
Inject short pauses, occasionaly, to fill out processing cycles to a specified rate. |
Check against a throttle speed without waiting. |
@todo Should always round the log base 100 down to the nearest integer?
@author Rupert Smith