[ 
https://issues.apache.org/jira/browse/HBASE-13686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14552301#comment-14552301
 ] 

Ashish Singhi commented on HBASE-13686:
---------------------------------------

The work of refillStrategy.refill is to give the number of resources that are 
refilled and that can then be checked and added to the existing avail to form a 
new avail.

bq. The canExecute() should not to handle the special case of refillStrategy
All the special case of refillStrategy is handled by themselves in {{refill}} 
method {{canExecute}} has only the code which will be common to all the 
refillStrategy after they finish calculating the refill amount and can avoid 
duplicating the code.

{quote}
Assume there is a RateLimiter which limit and avail is Long.MAX_VALUE. Then 
consume(1). The avail will be Long.MAX_VALUE - 1. After a long time, 
canExecute(1) again. This will refill again. The delta will be much greater 
than 1. Then available + delta will be negative.
{quote}
This you have already answered in your first comment that **"check positive 
overflow" can catch this case**. So I feel better to leave this piece of code 
in {{canExecute}} only and avoid duplicating this code in each refill method as 
of now.

I do not see any strong reason to move this code in {{refill}} of each 
{{RefillStrategy}}

> Fail to limit rate in RateLimiter
> ---------------------------------
>
>                 Key: HBASE-13686
>                 URL: https://issues.apache.org/jira/browse/HBASE-13686
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 2.0.0, 1.1.0
>            Reporter: Guanghao Zhang
>            Assignee: Ashish Singhi
>             Fix For: 2.0.0, 1.2.0, 1.1.1
>
>         Attachments: HBASE-13686.patch
>
>
> While using the patch in HBASE-11598 , I found that RateLimiter can't to 
> limit the rate right.
> {code} 
>  /**
>    * given the time interval, are there enough available resources to allow 
> execution?
>    * @param now the current timestamp
>    * @param lastTs the timestamp of the last update
>    * @param amount the number of required resources
>    * @return true if there are enough available resources, otherwise false
>    */
>   public synchronized boolean canExecute(final long now, final long lastTs, 
> final long amount) {
>     return avail >= amount ? true : refill(now, lastTs) >= amount;
>   }
> {code}
> When avail >= amount, avail can't be refill. But in the next time to call 
> canExecute, lastTs maybe update. So avail will waste some time to refill. 
> Even we use smaller rate than the limit, the canExecute will return false. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to