public class ThroughputThrottler extends 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.
|
void |
wakeup()
Wakeup the throttler if its sleeping.
|
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()
public void wakeup()