Skip to content
Merged
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 @@ -363,17 +363,24 @@ public BackgroundTaskQueue getTasks() {
private boolean shouldDelay() {
// We should wait for next AvailableTime.
if (Time.monotonicNow() <= nextAvailableTime.get()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping balancing until nextAvailableTime ({} ms)",
(nextAvailableTime.get() - Time.monotonicNow()));
}
return true;
}
// Calculate the next AvailableTime based on bandwidth
long bytesBalanced = balancedBytesInLastWindow.getAndSet(0L);

final int megaByte = 1024 * 1024;

// converting disk bandwidth in byte/millisec
float bytesPerMillisec = bandwidthInMB * megaByte / 1000f;
nextAvailableTime.set(Time.monotonicNow() +
((long) (bytesBalanced / bytesPerMillisec)));
long delayInMillisec = (long) (bytesBalanced / bytesPerMillisec);
nextAvailableTime.set(Time.monotonicNow() + delayInMillisec);
if (LOG.isDebugEnabled()) {
LOG.debug("Bytes balanced: {} MB, Calculated delay: {} ms ({} sec)",
bytesBalanced / megaByte, delayInMillisec, delayInMillisec / 1000);
}
return false;
}

Expand Down Expand Up @@ -446,6 +453,7 @@ public BackgroundTaskResult call() {
}
oldContainer.getContainerData().getVolume()
.decrementUsedSpace(containerSize);
balancedBytesInLastWindow.addAndGet(containerSize);
metrics.incrSuccessCount(1);
metrics.incrSuccessBytes(containerSize);
} catch (IOException e) {
Expand Down