You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by dm...@apache.org on 2013/03/22 20:02:04 UTC

svn commit: r1459930 - /hbase/trunk/src/docbkx/performance.xml

Author: dmeil
Date: Fri Mar 22 19:02:03 2013
New Revision: 1459930

URL: http://svn.apache.org/r1459930
Log:
hbase-8180.  performance.xml.  Adding entry for using byte-array constants.

Modified:
    hbase/trunk/src/docbkx/performance.xml

Modified: hbase/trunk/src/docbkx/performance.xml
URL: http://svn.apache.org/viewvc/hbase/trunk/src/docbkx/performance.xml?rev=1459930&r1=1459929&r2=1459930&view=diff
==============================================================================
--- hbase/trunk/src/docbkx/performance.xml (original)
+++ hbase/trunk/src/docbkx/performance.xml Fri Mar 22 19:02:03 2013
@@ -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>