{"id":1385,"date":"2011-07-06T18:40:13","date_gmt":"2011-07-06T23:40:13","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=1385"},"modified":"2011-07-06T18:43:21","modified_gmt":"2011-07-06T23:43:21","slug":"simple-hbase-stress-tester","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2011\/07\/06\/simple-hbase-stress-tester\/","title":{"rendered":"Simple HBase stress tester"},"content":{"rendered":"<p>What is below is a simple class to read a random set of records from a table.  This should be a good start if you are looking for a simple one class test case, that may also be useful for simple stress testing.<\/p>\n<p>As other example regarding HBase, it assumes you have configured your hbase-site.xml with the location of your HBase database.<\/p>\n<pre lang=\"java\" line=\"1\">\r\nimport java.util.*;\r\nimport org.apache.hadoop.hbase.client.*;\r\nimport org.apache.hadoop.hbase.util.*;\r\n\r\nclass hbaseStresser implements Runnable {\r\n  Thread t;\r\n\r\n  public static void main(String args[]) {\r\n    try {\r\n\r\n      System.out.println(new java.util.Date());\r\n      for(int i=1; i <= Integer.parseInt(args[0]); i++){  \/\/pass in the number of threads you want to run\r\n        hbaseStresser r = new hbaseStresser();\r\n      }\r\n    }\r\n    catch(Exception e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n\r\n  hbaseStresser() {\r\n    try {\r\n      t = new Thread(this);\r\n      t.start();\r\n    }\r\n    catch (Exception e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n\r\n  public void run() {\r\n    try {\r\n      HTable hTable = new HTable(\"t1\");  \/\/this is your table name\r\n\r\n      byte[] rowId = null;\r\n      byte[] famA = Bytes.toBytes(\"data\");  \/\/this is your column family\r\n      byte[] col1 = Bytes.toBytes(\"xml\"); \/\/this is your on the fly column name in the table\r\n\r\n      Random rId = new Random();\r\n      for (int j = 1; j < 1000; j++) {  \/\/each thread loops 1000 times\r\n        int id = rId.nextInt(100000000); \/\/and randomly selects a record with an id between 1 and 100 million\r\n        rowId = Bytes.toBytes(Integer.toString(id));\r\n        Get get = new Get(rowId);\r\n        Result result = hTable.get(get);\r\n        byte[] value = result.getValue(famA, col1);\r\n        System.out.println(id);\r\n        System.out.println(Bytes.toString(value));\r\n      }\r\n    }\r\n    catch (Exception e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is below is a simple class to read a random set of records from a table. This should be a good start if you are looking for a simple one class test case, that may also be useful for&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2011\/07\/06\/simple-hbase-stress-tester\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,20],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/1385"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1385"}],"version-history":[{"count":9,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/1385\/revisions"}],"predecessor-version":[{"id":1394,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/1385\/revisions\/1394"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1385"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}