博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HiveServer2连接ZooKeeper出现Too many connections问题的解决
阅读量:7009 次
发布时间:2019-06-28

本文共 3524 字,大约阅读时间需要 11 分钟。

作者: | 文章可以转载,请以超链接形式标明文章原始出处和作者信息

网址:

HiveServer2支持多客户端的并发访问,使用ZooKeeper来管理Hive表的读写锁。实际环境中,遇到了HiveServer2连接ZooKeeper出现Too many connections的问题,这里是对这一问题的排查和解决过程。

问题描述

HiveServer2服务无法执行hive命令,日志中提示如下错误:

2013-03-22 12:54:43,946 WARN  zookeeper.ClientCnxn (ClientCnxn.java:run(1089)) - Session 0x0 for server hostname/***.***.***.***:2181, unexpected error, closing socket connection and attempting reconnectjava.io.IOException: Connection reset by peer        at sun.nio.ch.FileDispatcher.read0(Native Method)        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:21)        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)        at sun.nio.ch.IOUtil.read(IOUtil.java:200)        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)        at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:68)        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:355)        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)

问题排查

1. 首先,根据HiveServer2的错误日志,提示是由于Connection reset by peer,即连接被ZooKeeper拒绝。

2. 进一步查看HiveServer2上所配置的ZooKeeper集群日志(用户Hive表的读写锁管理),发现如下错误信息:

2013-03-22 12:52:48,938 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@193] - Too many connections from /***.***.***.*** - max is 50

3. 结合HiveServer2的日志,可见是由于HiveServer2所在机器对ZooKeeper的连接数超过了ZooKeeper设置允许的单个client最大连接数(这里是50)。

4. 我们进一步确认了是不是完全都是HiveServer2占用了这50个连接,显示确实是HiveServer2进程内部占用了这50个连接(进程号26871即为HiveServer2进程):

[user@hostname ~]$ sudo netstat -nap  | grep 2181tcp    0      0 ***.***.***.***:58089   ***.***.***.***:2181    ESTABLISHED 26871/java          tcp    0      0 ***.***.***.***:57837   ***.***.***.***:2181    ESTABLISHED 26871/java          tcp    0      0 ***.***.***.***:57853   ***.***.***.***:2181    ESTABLISHED 26871/java         ……(共计50个)

5. 为什么HiveServer2会占用这么多连接?而实际并发请求量并没有这么多。只能从HiveServer2的实现原理找找线索,由于HiveServer2是通过Thrift实现的,怀疑是不是其内部维护连接池导致的?经过查看hive-default.xml中发现,其中默认配置了工作线程数(这里猜测每个工作线程会维护一个与ZooKeeper的连接,有待从代码级别进行验证)

hive.server2.thrift.min.worker.threads
5
Minimum number of Thrift worker threads
hive.server2.thrift.max.worker.threads
100
Maximum number of Thrift worker threads

问题解决

方法一:

通过在hive-site.xml中修改HiveServer2Thrift工作线程数,减少与ZooKeeper的连接请求数。这样可能降低HiveServer2的并发处理能力。

方法二:

通过修改ZooKeeperzoo.cfg文件中的maxClientCnxns选项,调大对于单个Client的连接数限制。

以上两个方法,需要根据自己的实际生产情况进行合理设置。

相关的配置选项:

1hive-site.xml中:

hive.server2.thrift.min.worker.threads
10
Minimum number of Thrift worker threads
hive.server2.thrift.max.worker.threads
200
Maximum number of Thrift worker threads
hive.zookeeper.session.timeout
60000
Zookeeper client's session timeout. The client is disconnected, and as a result, all locks released, if a heartbeat is not sent in the timeout.

2zoo.cfg中:

# Limits the number of concurrent connections (at the socket level) that a single client, identified by IP addressmaxClientCnxns=200# The minimum session timeout in milliseconds that the server will allow the client to negotiateminSessionTimeout=1000# The maximum session timeout in milliseconds that the server will allow the client to negotiatemaxSessionTimeout=60000
你可能感兴趣的文章
xmapp 404设置
查看>>
[js - 算法可视化] 汉诺塔(Hanoi)演示程序
查看>>
Note:JSON
查看>>
分享.NET 3.0的书籍下载(持续更新中)
查看>>
几道有意思的逻辑分析题
查看>>
apache svn下新建一个项目
查看>>
高效 JavaScript 单元测试(转)
查看>>
[Windows Azure] What is a cloud service?
查看>>
使用C#的泛型队列Queue实现生产消费模式
查看>>
tomcat发布web项目,支持域名
查看>>
js和Jquery获取选中select值和文本
查看>>
Linux系统排查1——内存篇
查看>>
Java实现注册邮箱激活验证
查看>>
数据库缓存
查看>>
mvc 数据验证金钱格式decimal格式验证
查看>>
常用的Web服务器
查看>>
UPW学习资料整理 .NET C# 转
查看>>
Oracle12c中新建用户
查看>>
分布式编译工具
查看>>
对我而言晦涩的递归
查看>>