public class ThroughputThrottler
extends java.lang.Object
if (throttler.shouldThrottle(...)) {
throttler.throttle();
}
Note that this can be used to throttle message throughput or data throughput.Constructor and Description |
---|
ThroughputThrottler(long targetThroughput,
long startMs) |
Modifier and Type | Method and Description |
---|---|
boolean |
shouldThrottle(long amountSoFar,
long sendStartMs) |
void |
throttle()
Occasionally blocks for small amounts of time to achieve targetThroughput.
|
public ThroughputThrottler(long targetThroughput, long startMs)
targetThroughput
- Can be messages/sec or bytes/secstartMs
- When the very first message is sentpublic boolean shouldThrottle(long amountSoFar, long sendStartMs)
amountSoFar
- bytes produced so far if you want to throttle data throughput, or
messages produced so far if you want to throttle message throughput.sendStartMs
- timestamp of the most recently sent messagepublic void throttle()