Database Reference
In-Depth Information
for (int i = 0; i < total; i++) {
int userid = i;
String email = "user-" + i + "@foo.com";
String phone = "555-1234";
byte[] key = Bytes.toBytes(userid);
Put put = new Put(key);
put.add(Bytes.toBytes(familyName), Bytes.toBytes("email"),
Bytes.toBytes(email));
put.add(Bytes.toBytes(familyName), Bytes.toBytes("phone"),
Bytes.toBytes(phone));
htable.put(put);
}
long t4b = System.currentTimeMillis();
System.out.println("inserted " + total + " users in " +
(t4b - t4a) + " ms");
hConnection.close();
}
}
A sample run yields the following timings:
Connection manager in : 98 ms
first connection in : 808 ms
second connection : 0 ms
inserted 100 users in 393 ms
The first connection takes a long time, but then take a look at the time of the second
connection. It is almost instant ! This is cool!
If you are connecting to HBase from web applications (or interactive
applications), use connection pooling.
More tips for high-performing HBase writes
Here we will discuss some techniques and best practices to improve writes in HBase.
 
Search WWH ::




Custom Search