开发者社区> 问答> 正文

Hbase client 不定期超时

public class HBaseClient {

public static final byte[] COLUMN_FAMILY = Bytes.toBytes("t");
private static Connection connection = null;
private static Logger logger = LoggerFactory.getLogger(HBaseClient.class);

static {
    try {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        conf.set("hbase.zookeeper.quorum", "hnode2,hnode4,hnode5");
        conf.setInt("hbase.rpc.timeout",1500);
        conf.setInt("hbase.client.operation.timeout",2000);
        conf.set("hbase.client.ipc.pool.type","RoundRobin");
        conf.set("hbase.client.ipc.pool.size", "100");
        connection = ConnectionFactory.createConnection(conf);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

private static Table getTable(String table) throws IOException {
    return connection.getTable(TableName.valueOf(table));
}

/**
 * 通过指定的table,key,field进行查询,暂时仅支持字符串类型
 * @param table 表名
 * @param key   查询rowkey
 * @param field 字段
 * @return  返回结果
 */
public static String query(String table,String key,String field){
    String column = "";
    try (Table tab = getTable(table)) {
        Get get = new Get(Bytes.toBytes(key));
        Cell cell = tab.get(get).getColumnLatestCell(COLUMN_FAMILY, Bytes.toBytes(field));
        if(cell != null) {
            column = Bytes.toString(CellUtil.cloneValue(cell));
        }
    } catch (Exception e) {
        logger.error("查询请求出错:" + e.getMessage());
        logger.error(e.toString());
    }
    return column;
}

。。。。
}
上面是我的客户端代码,总是不定期,一组超时。超时结束的时间特别巧,都是同一时间点:
2018-04-19 10:27:22,387 [http-nio-0.0.0.0-8401-exec-2] INFO com.x.data.xclient.service.RecommendService:54 - requestId:1001_1_4839597_null_1524104839135 耗时:3153
2018-04-19 10:27:22,409 [http-nio-0.0.0.0-8401-exec-7] INFO com.x.data.xclient.service.RecommendService:54 - requestId:1001_1_6560661_null_1524104833326 耗时:8997
2018-04-19 10:27:22,410 [http-nio-0.0.0.0-8401-exec-1] INFO com.x.data.xclient.service.RecommendService:54 - requestId:1001_1_4633235_null_1524104838673 耗时:3658
2018-04-19 10:27:22,442 [http-nio-0.0.0.0-8401-exec-5] INFO com.x.data.xclient.service.RecommendService:54 - requestId:1002_2_null_1922268_1524104831961 耗时:10401
2018-04-19 10:27:22,445 [http-nio-0.0.0.0-8401-exec-9] INFO com.x.data.xclient.service.RecommendService:54 - requestId:1001_1_2041887_null_1524104835395 耗时:6970
2018-04-19 10:27:22,445 [http-nio-0.0.0.0-8401-exec-10] INFO com.x.data.xclient.service.RecommendService:54 - requestId:1001_1_3392255_null_1524104833065 耗时:9327
2018-04-19 10:27:22,451 [http-nio-0.0.0.0-8401-exec-8] INFO com.x.data.xclient.service.RecommendService:54 - requestId:1001_1_4796956_null_1524104837966 耗时:4432
2018-04-19 10:27:22,468 [http-nio-0.0.0.0-8401-exec-11] INFO com.x.data.xclient.service.RecommendServi

展开
收起
hbase小能手 2018-11-07 11:30:41 3133 0
2 条回答
写回答
取消 提交回答
  • 前一个帐号wangccsy@126.com不知道怎么的就成了企业帐号,改不成个人。所以重新注册了一个个人帐号。老程序员。精通JAVA,C#,数据库,对软件开发过程和流程熟悉。考取系统分析师,项目管理师和系统架构设计师等软件资格考试认证。愿意和大家一起前进。

    是否可以将超时时长增加一些。

    2019-07-17 23:12:40
    赞同 展开评论 打赏
  • 社区管理员

    你查看一下日志 那个时间段是不是Hbase由于JVM GC导致超时的

    2019-07-17 23:12:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
大数据时代的存储 ——HBase的实践与探索 立即下载
Hbase在滴滴出行的应用场景和最佳实践 立即下载
阿里云HBase主备双活 立即下载