hbase-connection reset by peer异常

bxpogfeg  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(437)

我正在尝试使用hbase来构建一些实时api。因此,我的用例支持每秒约10000个并发请求。我试图做一些连接池,以便实现多线程访问。我按照以下文档创建连接:https://hbase.apache.org/1.1/apidocs/org/apache/hadoop/hbase/client/connectionfactory.html
但当我对api进行并发请求时,总是会出现以下错误:

WARN [http-nio-34000-exec-93-SendThread(d-3zjyk02.target.com:2181)] 
19 Apr 2017 04:48:13:872 (ClientCnxn.java:1102) - Session 0x0 for 
server d-3zjyk02.target.com/10.66.241.30:2181, unexpected error, 
closing socket connection and attempting reconnect
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:68)
at 

org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:366)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)

以下是我创建连接的方式:

// Connection to the cluster. A single connection shared by all application threads
private Connection connection = null;

public Connection getHBaseConnection() throws Exception {
    if (connection == null) {
        try {
            Configuration configuration = HBaseConfiguration.create();
            configuration.addResource("core-site.xml");
            configuration.addResource("hbase-site.xml");
            configuration.addResource("hdfs-site.xml");
            connection = ConnectionFactory.createConnection(configuration);

        } catch (Exception ex) {
            LOG.error("Exception in creating the HBase connection object: " + ex.getMessage());
            throw new Exception("Exception in creating the HBase connection: " + ex.getMessage());
        }
    }
    return connection;
}

下面是如何使用get hbase connection方法执行一些扫描操作:

try {
        connection = getHBaseConnection();
        afterConnectionStartTime = System.currentTimeMillis();
        LOG.info("[" + (System.currentTimeMillis() - startTime) + "]ms" + " ...TIME TAKEN to get the HBase connection object");
        if (connection != null) {
            table = connection.getTable(TableName.valueOf(TABLE_NAME));
            Scan scan = new Scan(Bytes.toBytes(rowKeyStartDate), Bytes.toBytes(rowKeyEndDate));
            scan.addColumn(COLUMN_FAMILY, ITEM);
}

这段代码对于任意数量的连续请求都可以很好地工作,但是当我执行并发请求时,总是会出现这个错误。
我在这个问题上的一些观察:
1) 这个错误与zookeeper在一定数量的请求后关闭套接字有关(我假设它超过了zoo.cfg文件中提到的最大客户端连接数(40))。但我不明白的是,为什么并发的请求会首先发送给zookeeper。第一个请求应打开连接对象,所有后续请求应使用该预先存在的连接直接与区域服务器通信。
2) 我假设这是连接池的正确方法(至少根据官方的hbase文档)。如果没有,正确的方法是什么?
3) 我不想增加zookeeper cfg文件中的最大客户端连接数,我认为这可能是一个临时的黑客可以做我的工作。
如有任何帮助/建议,我们将不胜感激。
谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题