Hbase常连接问题
Hiwes 2018-04-08 11:11:19 各位大佬好,新接触到HBase数据库,建立了一个用户推荐结果表,以用户ID作为rowkey。现有性能需求需做到:当携带用户ID参数的http消息发送来之后,能在100ms内返回一个推荐结果字符串,即:用100ms来进行HBase数据库的查询。
我在编写HBase工具类的时候,使用了单件模式,代码如下:
public HBaseAdmin admin = null;
public Configuration conf = null;
public Connection conn = null;
//私有构造方法:加载一些必要的参数
private HBaseUtils() {
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "master:2181");
conf.set("hbase.rootdir", "hdfs://hy:9000/hbase");
try {
conn=ConnectionFactory.createConnection(conf);
admin = new HBaseAdmin(conf);
} catch (IOException e) {
e.printStackTrace();
}
}
private static HBaseUtils instance = null;
public static synchronized HBaseUtils getInstance() {
if (null == instance) {
instance = new HBaseUtils();
}
return instance;
}
/**
* 根据表名获取到HTable实例
*/
public HTable getTable(String tableName) {
HTable table = null;
try {
table = new HTable(conf, tableName);
} catch (IOException e) {
e.printStackTrace();
}
return table;
}
但是我在测试的时候,每次都是第一次查询时间长达1、2000ms,后面的基本都是在ms级别。
问了一位前辈,说要进行HBase的常连接,但我还是不太清楚具体怎么实现。向各位大佬请教下,具体怎么实现HBase的常连接?即第一次连接之后,后面我每一次查询,都能在ms级别返回结果。