我的客户端正在使用 org.apache.hbase:hbase-client:2.1.0"
并且服务器正在运行 1.2.0-cdh5.11.1
(1.2.0-cdh5.11.0
在另一个测试集群中)。
我的客户端非常简单,它在启动时实例化了一个 Connection
类(这个类 - 正如 Apache 推荐的那样 - 跨线程共享,因为它很重并且线程安全)。然后对于每个请求,它创建一个 Table
类并执行 .exists(new Get(rowKey))
操作。
像这样:
Connection conn = ConnectionFactory.createConnection(hbaseConfig);
和
final Table table = conn.getTable(tableName);
return table.exists(new Get(context.getKey()));
大多数情况下,到 HBase 和返回的请求延迟最差为 40 毫秒。通常它会在 10 毫秒左右完成。
但是,我们注意到偶尔的请求需要大约 5000 毫秒 (5s) - 但仍然成功完成!
我所说的偶尔是指每分钟大约 1 个请求(总共每分钟 600 个请求,所以速率很小)。但它很稳定。
这些几乎正好在 5 秒左右(+/- 100-200 毫秒)。那是奇怪的部分。这不是尖峰。
起初我怀疑这是客户端配置错误,我需要设置更严格的超时,所以我设置了以下内容:
hbaseConfig.set(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
hbaseConfig.set(HConstants.HBASE_CLIENT_PAUSE, "50");
hbaseConfig.set(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, "2000");
hbaseConfig.set(HConstants.HBASE_RPC_TIMEOUT_KEY, "1500");
hbaseConfig.set(HConstants.HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY, "2000");
hbaseConfig.set(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, "1500");
hbaseConfig.set(HConstants.ZOOKEEPER_RECOVERABLE_WAITTIME, "2000");
hbaseConfig.set(HConstants.ZK_SESSION_TIMEOUT, "2000");
hbaseConfig.set("zookeeper.recovery.retry", "1");
hbaseConfig.set("zookeeper.recovery.retry.intervalmill","200");
hbaseConfig.set("hbase.ipc.client.socket.timeout.connect", "2000");
hbaseConfig.set("hbase.ipc.client.socket.timeout.read", "2000");
hbaseConfig.set("hbase.ipc.client.socket.timeout.write", "2000");
换句话说,5000 毫秒超过了全局超时(在 HConstants.HBASE_CLIENT_OPERATION_TIMEOUT
中设置)。
但我有需要大约 5 秒才能完成的请求 - 并且成功完成。
除了这些超时之外,我还从使用 AsyncConnection
更改为 Connection
(无论如何都不需要它是异步的)并且我正在考虑制作 GET
调用而不是 exists
。
但在这一点上我被难住了。我没有看到任何属性(property),也没有看到 5s 的来源。连超时都没有,居然成功了!
有没有人遇到过这个?有没有办法让 hbase-client 发出指标?服务器端指标显示延迟没有增加(扫描指标)。
最佳答案
对于我们来说,线程转储显示时间花在了使用 IPv6 实现执行 DNS 解析上,并且还发现了一些关于 native 库延迟 5 秒的问题。
hconnection-0x6fc1d215-shared--pool1-t95"
java.lang.Thread.State: RUNNABLE
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getAllByName0(InetAddress.java:1277)
at java.net.InetAddress.getAllByName(InetAddress.java:1193)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
at java.net.InetAddress.getByName(InetAddress.java:1077)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:220)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getStubKey(ConnectionManager.java:1802)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getClient(ConnectionManager.java:1772)
at org.apache.hadoop.hbase.client.ScannerCallable.prepare(ScannerCallable.java:163)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas$RetryingRPC.prepare(ScannerCallableWithReplicas.java:409)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:134)
at org.apache.hadoop.hbase.client.ResultBoundedCompletionService$QueueingFuture.run(ResultBoundedCompletionService.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)"Timer-47"
https://github.com/netty/netty/issues/6454
添加 -Djava.net.preferIPv4Stack=true
以强制使用 IPv4 堆栈似乎已经为我们解决了这个问题。我们再也看不到 5 秒的延迟(祈祷)
关于java - 尽管超时时间较低,但稳定数量的 HBase 请求几乎正好需要 5000 毫秒才能完成(成功)。不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54644568/