[ https://issues.apache.org/jira/browse/HBASE-13686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14544883#comment-14544883 ]
Guanghao Zhang commented on HBASE-13686: ---------------------------------------- This is a new TestCase in TestRateLimiter. {code} @Test public void testLimiterBySmallerRate() throws InterruptedException { RateLimiter limiter = new RateLimiter(); // set limiter is 10 resources per seconds limiter.set(10, TimeUnit.SECONDS); long lastTs = System.currentTimeMillis(); int count = 0; // control the test count while ( (count++) < 100) { // test will get 3 resources per 0.5 sec. so it will get 6 resources per sec. Thread.sleep(500); for (int i = 0; i < 3; i++) { long nowTs = System.currentTimeMillis(); // 6 resources/sec < limit, so limiter.canExecute(nowTs, lastTs) should be true assertEquals(true, limiter.canExecute(nowTs, lastTs)); limiter.consume(); lastTs = nowTs; } } } {code} > 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 > Priority: Minor > > 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)