[
https://issues.apache.org/jira/browse/HADOOP-14896?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16175843#comment-16175843
]
Zhizhen Hou commented on HADOOP-14896:
--------------------------------------
After first loop in while, if a major gc occurred, and gc time longer than
periodExtension. When the thread resumed, curReserve = bytesPerPeriod -
bytesAlreadyUsed; will be called, and curReserve will be a negative value.
{code:java}
/** Given the numOfBytes sent/received since last time throttle was called,
* make the current thread sleep if I/O rate is too fast
* compared to the given bandwidth. Allows for optional external cancelation.
*
* @param numOfBytes
* number of bytes sent/received since last time throttle was called
* @param canceler
* optional canceler to check for abort of throttle
*/
public synchronized void throttle(long numOfBytes, Canceler canceler) {
if ( numOfBytes <= 0 ) {
return;
}
curReserve -= numOfBytes;
bytesAlreadyUsed += numOfBytes;
while (curReserve <= 0) {
if (canceler != null && canceler.isCancelled()) {
return;
}
long now = monotonicNow();
long curPeriodEnd = curPeriodStart + period;
if ( now < curPeriodEnd ) {
// Wait for next period so that curReserve can be increased.
try {
wait( curPeriodEnd - now );
} catch (InterruptedException e) {
// Abort throttle and reset interrupted status to make sure other
// interrupt handling higher in the call stack executes.
Thread.currentThread().interrupt();
break;
}
} else if ( now < (curPeriodStart + periodExtension)) {
curPeriodStart = curPeriodEnd;
curReserve += bytesPerPeriod;
} else {
// discard the prev period. Throttler might not have
// been used for a long time.
curPeriodStart = now;
curReserve = bytesPerPeriod - bytesAlreadyUsed;
}
}
bytesAlreadyUsed -= numOfBytes;
}
{code}
> Throttle will behave unexpected when gc time longer than periodExtension
> ------------------------------------------------------------------------
>
> Key: HADOOP-14896
> URL: https://issues.apache.org/jira/browse/HADOOP-14896
> Project: Hadoop Common
> Issue Type: Bug
> Components: common
> Affects Versions: 2.7.2
> Reporter: Zhizhen Hou
>
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]