【问题标题】:How to set time limit for creating HBase connection如何设置创建 HBase 连接的时间限制
【发布时间】:2015-07-10 18:28:51
【问题描述】:

我目前正在使用 HBase v0.98.6。我想从外部 Java 程序检查当前连接状态。现在,我正在做这样的事情来检查:

connectionSuccess = true;
try {
     HConnection hConnection = createConnection(config);
} catch (Exception ex) {
     connectionSuccess = false;
}

当连接工作时,它会很快返回。问题是当连接不工作时,它需要 20 分钟才能最终返回connectionSuccess=false。有没有办法减少这个时间限制,因为我只想在当前时间获取连接状态?

【问题讨论】:

标签: java hbase


【解决方案1】:

需要这么长时间的原因是,默认情况下如果连接失败,它会重试多次(我认为是 6?不要引用我的话),并且每次连接尝试都需要一段时间。尝试组合使用这些命令来限制超时前每个连接的时间,以及允许的重试尝试次数。

hbase.client.retries.number = 3
hbase.client.pause = 1000
zookeeper.recovery.retry = 1(即不重试)

感谢 Lars 来自 http://hadoop-hbase.blogspot.com/2012/09/hbase-client-timeouts.html

【讨论】:

    【解决方案2】:

    您可以将 retries 值设置为 1 以获取当前时间的连接状态。

    Configuration conf = HBaseConfiguration.create();
    conf.setInt("hbase.client.retries.number",1);
    conf.setInt("zookeeper.recovery.retry",0);
    

    或者你可以使用下面的内置 HbaseAdmin 方法来做同样的事情。

    connectionSuccess = true;
    try
    {
      HBaseAdmin.checkHBaseAvailable(config);
    }
    catch(MasterNotRunningException e)
    {
      connectionSuccess = false;
    }
    

    【讨论】:

      【解决方案3】:

      我的 org.apache.hadoop.conf.Configuration 对象包含以下键值对:

      Configuration conf = HBaseConfiguration.create();
      
      //configuring timeout and retry parameters
      conf.set("hbase.rpc.timeout", "10000");
      conf.set("hbase.client.scanner.timeout.period", "10000");
      conf.set("hbase.cells.scanned.per.heartbeat.check", "10000");
      conf.set("zookeeper.session.timeout", "10000");
      conf.set("phoenix.query.timeoutMs", "10000");
      conf.set("phoenix.query.keepAliveMs", "10000");
      conf.set("hbase.client.retries.number", "3");
      conf.set("hbase.client.pause", "1000");
      conf.set("zookeeper.recovery.retry", "1");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-13
        • 1970-01-01
        • 1970-01-01
        • 2011-02-25
        • 2021-12-21
        • 1970-01-01
        相关资源
        最近更新 更多