HBase连接池用于非常频繁地扫描行

abh*_*eet 1 java hbase

我必须在一小时内非常频繁地扫描表格(〜百万次).我有关于rowid的信息(这是一个字节数组).我正在创建用于创建startrow和endrow的rowid,这在我的情况下基本相同.

     public String someMethod(byte[] rowid){
            if (aTable == null) {
                  aTable = new HTable(Config.getHadoopConfig(),
                  Config.getATable());     
            }
            byte[] endRow = new byte[rowId.length];
            endrow = System.copyArray(rowId, 0, endRow, 0, rowId.length)
            Scan scan = new Scan(rowId , endRow)
            //scanner implementation and iteration over the result
            (ResultScanner result = aTable.getScanner(scan);) {
                   for (Result item : result) {

                   }
            }
     }
Run Code Online (Sandbox Code Playgroud)

我想知道我是否可以实现一些连接池来提高性能.是否存在HBase Java API中可用的任何池化机制.我使用的是0.96.x版本的HBase.此外,是否有任何配置设置可以提高性能.谢谢

小智 10

自1.0版以来,连接池API已更改.

新的API代码供读者参考:

// Create a connection to the cluster.
Configuration conf = HBaseConfiguration.create();
try (Connection connection = 
  ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf(tablename))) {
// use table as needed, the table returned is lightweight
}
Run Code Online (Sandbox Code Playgroud)

  • 这个连接池如何?ConnectionFactory.createConnection 中的代码每次都会创建一个新连接!在连接池中,我们预先创建了 N 个。连接数和池根据需要增长或缩小。这段代码不这样做,对吧? (2认同)