hbase-8180. performance.xml. Adding entry for using byte-array constants.

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1459930 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Meil 2013-03-22 19:02:03 +00:00
parent f7d02a07d8
commit 423f0742e3
1 changed files with 25 additions and 0 deletions

View File

@ -287,6 +287,31 @@
</section>
</section> <!-- perf schema -->
<section xml:id="perf.general">
<title>HBase General Patterns</title>
<section xml:id="perf.general.constants">
<title>Constants</title>
<para>When people get started with HBase they have a tendency to write code that looks like this:
<programlisting>
Get get = new Get(rowkey);
Result r = htable.get(get);
byte[] b = r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns current version of value
</programlisting>
But especially when inside loops (and MapReduce jobs), converting the columnFamily and column-names
to byte-arrays repeatedly is surprsingly expensive.
It's better to use constants for the byte-arrays, like this:
<programlisting>
public static final byte[] CF = "cf".getBytes();
public static final byte[] ATTR = "attr".getBytes();
...
Get get = new Get(rowkey);
Result r = htable.get(get);
byte[] b = r.getValue(CF, ATTR); // returns current version of value
</programlisting>
</para>
</section>
</section>
<section xml:id="perf.writing">
<title>Writing to HBase</title>