org.apache.qpid.junit.extensions
Class BatchedThrottle
java.lang.Object
org.apache.qpid.junit.extensions.BaseThrottle
org.apache.qpid.junit.extensions.BatchedThrottle
- All Implemented Interfaces:
- Throttle
public class BatchedThrottle
- extends BaseThrottle
BatchedThrottle is a SleepThrottle
that uses batching to achieve much higher throttling rates than a sleep
throttle 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 throttle()
method, and using a sleep throttle run at a lower rate. The rate for the sleep
throttle 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 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?
Field Summary |
(package private) int |
batchSize
Holds the batch size. |
(package private) long |
callCount
The call count within the current batch. |
Method Summary |
void |
setRate(float hertz)
Specifies the throttling rate in operations per second. |
void |
throttle()
Throttle calls to this method to the rate specified by the setRate(float) method. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
batchSize
int batchSize
- Holds the batch size.
callCount
long callCount
- The call count within the current batch.
BatchedThrottle
public BatchedThrottle()
setRate
public void setRate(float hertz)
- Specifies the throttling rate in operations per second.
- Specified by:
setRate
in interface Throttle
- Overrides:
setRate
in class BaseThrottle
- Parameters:
hertz
- The throttling rate in cycles per second.
throttle
public void throttle()
- Throttle calls to this method to the rate specified by the
setRate(float)
method.
Licensed to the Apache Software Foundation