Database Reference
In-Depth Information
Profiling HBase applications
Just like any software development process, once we have our HBase application
working correctly, we would want to make it faster. At times, developers get too
carried away and start optimizing before the application is finalized. There is a
well-known rule that premature optimization is the root of all evil. One of the
sources for this rule is Scott Meyers Effective C++.
We can perform some ad hoc profiling in our code by timing various function calls.
Also, we can use profiling tools to pinpoint the trouble spots. Using profiling tools
is highly encouraged for the following reasons:
• Profiling takes out the guesswork (and a good majority of developers'
guesses are wrong).
• There is no need to modify the code. Manual profiling means that we have
to go and insert the instrumentation code all over the code. Profilers work
by inspecting the runtime behavior.
• Most profilers have a nice and intuitive UI to visualize the program flow
and time flow.
The authors use JProfiler. . It is a pretty effective profiler. However, it is neither free
nor open source. So, for the purpose of this chapter, we are going to show you a
simple manual profiling, as follows:
public class UserInsert {
static String tableName = "users";
static String familyName = "info";
public static void main(String[] args) throws Exception {
Configuration config = HBaseConfiguration.create();
// change the following to connect to remote clusters
// config.set("hbase.zookeeper.quorum", "localhost");
long t1a = System.currentTimeMillis();
HTable htable = new HTable(config, tableName);
long t1b = System.currentTimeMillis();
System.out.println ("Connected to HTable in : " +
(t1b-t1a) + " ms");
int total = 100;
long t2a = System.currentTimeMillis();
for (int i = 0; i < total; i++) {
int userid = i;
String email = "user-" + i + "@foo.com";
 
Search WWH ::




Custom Search