Index: src/docbkx/performance.xml =================================================================== --- src/docbkx/performance.xml (revision 1459918) +++ src/docbkx/performance.xml (working copy) @@ -287,6 +287,31 @@ +
+ HBase General Patterns +
+ Constants + When people get started with HBase they have a tendency to write code that looks like this: + +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 + + 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: + +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 + + +
+ +
Writing to HBase