Created
August 12, 2015 06:24
-
-
Save seregasheypak/00ef1a44e6293d13e56e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Typical put implmentation | |
public boolean put(SomeBean bean){ | |
HTableInterface hTable = null; | |
try { | |
//Controller holds reference to HConnection. | |
//It's created once during servlet.init in servlet and shared across several controllers, just an object ref | |
HConnection hConnection = getConnection(); | |
hTable = hConnection.getTable(getName()); | |
return hTable.checkAndPut(createKey(bean), CF_B, CQ_B, null, createPut(bean)); | |
} | |
catch (Exception e){ | |
LOG.error("Error while putting ["+bean+"]", e); | |
} | |
finally{ | |
close(hTable); | |
} | |
return false; | |
} | |
public void run() throws InterruptedException { | |
System.out.println("Going to run: ["+this+"]"); | |
Configuration configuration = new Configuration(); | |
configuration.set("hbase.zookeeper.property.clientPort", "2181"); | |
configuration.set("hbase.zookeeper.quorum", "node01,node2,node3"); | |
BusinessLogicController controller = new BusinessLogicController(); | |
//create single HConnection once | |
controller.setConfiguration(configuration); | |
ExecutorService service = Executors.newFixedThreadPool(treadCount); | |
CountDownLatch latch = new CountDownLatch(treadCount); | |
for (int threadNum=0; threadNum < treadCount; threadNum++) { | |
service.submit(() -> { | |
try { | |
for (int iterationNum = 0; iterationNum < iterationsCount; iterationNum++) { | |
Timer.Context timer = metricRegistry.timer("putTimer").time(); | |
controller.doSomeStuffHereWithRandomInput(); | |
timer.stop(); | |
metricRegistry.meter("putMeter").mark(); | |
} | |
} finally { | |
latch.countDown(); | |
} | |
}); | |
} | |
try { | |
latch.await(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
service.shutdown(); | |
service.awaitTermination(30, TimeUnit.MINUTES); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment