Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -733,22 +733,26 @@ public void throttle() throws InterruptedException {
if (throttleLimitMsPerSec > 0L) {
final long runningTime = throttleTimer.now(TimeUnit.MILLISECONDS);
if (runningTime >= throttleLimitMsPerSec) {
final long sleepTime;
if (runningTime >= 1000L) {
LOG.warn("Unable to throttle within the second. Blocking for 1s.");
sleepTime = 1000L;
} else {
// Sleep for the expected time plus any time processing ran over
final long overTime = runningTime - throttleLimitMsPerSec;
sleepTime = (1000L - throttleLimitMsPerSec) + overTime;
}
Thread.sleep(sleepTime);
Thread.sleep(calculateSleepTime(runningTime));
throttleTimer.reset().start();
}
accumulateTimeWaiting();
}
}

@VisibleForTesting
long calculateSleepTime(long runningTime) {
if (throttleLimitMsPerSec <= 0) return 0;
if (runningTime >= 1000L) {
LOG.warn("Unable to throttle within the second. Blocking for 1s.");
return 1000L;
} else {
// Sleep for the expected time plus any time processing ran over
final long overTime = runningTime - throttleLimitMsPerSec;
return (1000L - throttleLimitMsPerSec) + overTime;
}
}

/**
* Helper method to measure time running.
*/
Expand Down
Loading