简体   繁体   English

Hbase连接池

[英]Hbase connection pool

I am trying to create hbase connection pool. 我正在尝试创建hbase连接池。 I have tried the below thing. 我试过以下的事情。 But I dont know the consequences. 但我不知道后果。 Will it affect my performance? 它会影响我的表现吗? Can anybody please help? 有人可以帮忙吗? Hosts can be remote or even local. 主机可以是远程的,甚至是本地的。

HashMap cons = new HashMap();
    public void getDataFromHbase(String host, String tableid){
        conf.set("hbase.zookeeper.quorum", host);
        ThreadPoolExecutor executor= (ThreadPoolExecutor) Executors.newCachedThreadPool();
        executor.setMaximumPoolSize(50);
        if(cons.get(host+"tableA_"+tableid) != null){
            table1 = cons.get(host+"tableA_"+tableid);
            table2 = cons.get(host+"tableB_"+tableid);
        }
        else{
            table1 = new HTable(conf,Bytes.toBytes("tableA_"+tableid),executor);
            table2 = new HTable(conf,Bytes.toBytes("tableB_"+tableid),executor);
            cons.put(host+"tableA_"+tableid,table1);
            cons.put(host+"tableB_"+tableid,table2);
        }
        Scan scan = new Scan();
        scan.addFamily(Bytes.toBytes("n"));
        scan.setCaching(1000);
        ResultScanner resultScanner = table1.getScanner(scan);
        ResultScanner resultScannerB = table2.getScanner(scan);
    }

I'd recommend HTablePool .. rather own connection management which is more error prone and hard to debug . 我推荐使用HTablePool ..而不是自己的连接管理,这更容易出错并且难以调试

Class HTablePool 类HTablePool

java.lang.Object org.apache.hadoop.hbase.client.HTablePool java.lang.Object org.apache.hadoop.hbase.client.HTablePool

All Implemented Interfaces: 所有已实现的接口:

Closeable, AutoCloseable 可关闭,AutoCloseable

Deprecated. 已过时。 Use HConnection.getTable(String) instead. 请改用HConnection.getTable(String)。

public class HTablePool extends Object implements Closeable 公共类HTablePool extends Object实现了Closeable

A simple pool of HTable instances. 一个简单的HTable实例池。 Each HTablePool acts as a pool for all tables. 每个HTablePool都充当所有表的池。 To use, instantiate an HTablePool and use getTable(String) to get an HTable from the pool. 要使用,请实例化一个HTablePool并使用getTable(String)从池中获取一个HTable。 This method is not needed anymore, clients should call HTableInterface.close() rather than returning the tables to the pool Once you are done with it, close your instance of HTableInterface by calling HTableInterface.close() rather than returning the tables to the pool with (deprecated) putTable(HTableInterface). 不再需要此方法,客户端应调用HTableInterface.close()而不是将表返回到池完成后,通过调用HTableInterface.close()关闭HTableInterface实例,而不是将表返回池中with(已弃用)putTable(HTableInterface)。 A pool can be created with a maxSize which defines the most HTable references that will ever be retained for each table. 可以使用maxSize创建池,该maxSize定义将为每个表保留的最多HTable引用。 Otherwise the default is Integer.MAX_VALUE. 否则,默认值为Integer.MAX_VALUE。

Pool will manage its own connections to the cluster. 池将管理自己与群集的连接。 See HConnectionManager . 请参阅 HConnectionManager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM