hbase-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "BELUGA BEHR (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HBASE-19684) BlockCacheKey toString Performance
Date Tue, 02 Jan 2018 22:47:00 GMT

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

BELUGA BEHR commented on HBASE-19684:
-------------------------------------

[~appy] All I'm doing is creating a list of 100K string with either the current implementation
or with

{code}
for (int i = 0; i < 100000; i++) {
  // Test 1: c.add(String.format("%s_%d", a, b));
  // Test 2: c.add(a.concat("_").concat(Long.toString(b)));
  // Test 3: c.add(new StringBuilder(a.length() + 21).append(a).append('_').append(b).toString());
  // Test 4: c.add(a + '_' + b);
}
{code}

The current code with _String.format_ takes about 320ms to complete the _concat implementation
takes about 29ms to complete.  As you point out, the absolute magnitude is small, but measurable.
 However, 100K items into and out of the cache is not that much so the savings, over time,
accrues.

Please consider patch as is.

> BlockCacheKey toString Performance
> ----------------------------------
>
>                 Key: HBASE-19684
>                 URL: https://issues.apache.org/jira/browse/HBASE-19684
>             Project: HBase
>          Issue Type: Improvement
>          Components: hbase
>    Affects Versions: 3.0.0
>            Reporter: BELUGA BEHR
>            Assignee: BELUGA BEHR
>            Priority: Trivial
>         Attachments: HBASE-19684.1.patch
>
>
> {code:titile=BlockCacheKey.java}
>   @Override
>   public String toString() {
>     return String.format("%s_%d", hfileName, offset);
>   }
> {code}
> I found through bench-marking that the following code is 10x faster.
> {code:titi\le=BlockCacheKey.java}
>   @Override
>   public String toString() {
>     return hfileName.concat("_").concat(Long.toString(offset));
>   }
> {code}
> Normally it wouldn't matter for a _toString()_ method, but this is comes into play because
{{MemcachedBlockCache}} uses it.
> {code:title=MemcachedBlockCache.java}
>   @Override
>   public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf) {
>     if (buf instanceof HFileBlock) {
>       client.add(cacheKey.toString(), MAX_SIZE, (HFileBlock) buf, tc);
>     } else {
>       if (LOG.isDebugEnabled()) {
>         LOG.debug("MemcachedBlockCache can not cache Cacheable's of type "
>             + buf.getClass().toString());
>       }
>     }
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message