[ https://issues.apache.org/jira/browse/HBASE-13686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14551834#comment-14551834 ]
Ashish Singhi commented on HBASE-13686: --------------------------------------- Thanks [~zghaobac] for reviewing the patch. bq. if limit and available is Long.MAX_VALUE, when delta > 0, available + delta will be negative When can this case occur ? I can think of only one scenario, that is client executing canExecute for the first time where nextRefillTime will still be equal to default value i.e., -1 and that case is been already handled by below code. {code} if (refillTime == -1) { // Till now no resource has been consumed. this.nextRefillTime.compareAndSet(nextRefillTime.get(), EnvironmentEdgeManager.currentTime()); return limit; } {code} bq. refill should return the new avail, not the refillAmount Why you think so ? the new avail value will be calculated based on this refillAmount in the canExecute which I thought is ok. > 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)