Java.io.IOException:Connection reset by peer problem handling

Source: Internet
Author: User

HiveServer2 supports concurrent access for multiple clients and uses zookeeper to manage read-write locks on hive tables. In the actual environment, encountered HiveServer2 connection zookeeper too many connections problem, here is the process of troubleshooting and resolution of this problem.

Problem description

The HiveServer2 service was unable to execute the Hive command, and the log prompts the following error:

2013-03-2212:54:43,946 WARN Zookeeper. Clientcnxn (ClientCnxn.java:run (1089))-session 0x0 for serverhostname/***.***.***.***:2181, unexpected error, closing Socket Connection Andattempting Reconnect
Java.io.IOException:Connection Reset by peer
Atsun.nio.ch.FileDispatcher.read0 (Native method)
Atsun.nio.ch.SocketDispatcher.read (socketdispatcher.java:21)
Atsun.nio.ch.IOUtil.readIntoNativeBuffer (ioutil.java:233)
Atsun.nio.ch.IOUtil.read (ioutil.java:200)
Atsun.nio.ch.SocketChannelImpl.read (socketchannelimpl.java:236)
Atorg.apache.zookeeper.ClientCnxnSocketNIO.doIO (clientcnxnsocketnio.java:68)
Atorg.apache.zookeeper.ClientCnxnSocketNIO.doTransport (clientcnxnsocketnio.java:355)
Atorg.apache.zookeeper.clientcnxn$sendthread.run (clientcnxn.java:1068)

Problem troubleshooting

1. First, according to HIVESERVER2 error log, the hint is due to connection reset by peer, that is, the connection is zookeeper rejected.

2. Further view the Zookeeper cluster log (read-write lock management for user hive tables) configured on the HiveServer2 to find the following error message:

2013-03-2212: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. Combined with the HiveServer2 log, it is apparent that the number of connections to the zookeeper by the HiveServer2 machine exceeds the maximum number of single client connections allowed (50) for the zookeeper setting.

4. We further confirmed that it was not entirely HiveServer2 that occupied the 50 connections, showing that the 50 connections were indeed occupied within the HIVESERVER2 process (process number 26871 is the HIVESERVER2 process):

[user@hostname~]$ sudo netstat-nap | grep2181
TCP 0 0 ***.***.***.***:58089 ***.***.***.***:2181 established 26871/java
TCP 0 0 ***.***.***.***:57837 ***.***.***.***:2181 established 26871/java
TCP 0 0 ***.***.***.***:57853 ***.***.***.***:2181 established 26871/java
......
(a total of 50)

5. Why HiveServer2 will occupy so many connections. The actual concurrent request volume is not so much. Only from the realization of the principle of HiveServer2 to find clues, because HiveServer2 is implemented through the thrift, suspicion is not its internal maintenance connection pool caused. It is found in the view hive-default.xml that the number of worker threads is configured by default (this guesses that each worker thread maintains a connection to the zookeeper that needs to be validated from the code level):

<property>
<name>hive.server2.thrift.min.worker.threads</name>
<value>5</value>
<description>minimum number Ofthrift workerthreads</description>
</property>
<property>
<name>hive.server2.thrift.max.worker.threads</name>
<value>100</value>
<description>maximum number Ofthrift worker threads</description>
</property>

Problem solving

Method One:

Reduce the number of connection requests to zookeeper by modifying the number of HIVESERVER2 thrift worker threads in Hive-site.xml. This may reduce the concurrency processing power of HiveServer2.

Method Two:

Increase the number of connections to a single client by modifying the MAXCLIENTCNXNS option in the Zookeeper Zoo.cfg file.

The above two methods need to be set according to their actual production conditions.

Related configuration options:

1) in Hive-site.xml:

<property>
<name>hive.server2.thrift.min.worker.threads</name>
<value>10</value>
<description>minimum number Ofthrift workerthreads</description>
</property>
<property>
<name>hive.server2.thrift.max.worker.threads</name>
<value>200</value>
<description>maximum number Ofthrift workerthreads</description>
</property>
<property>
<name>hive.zookeeper.session.timeout</name>
<value>60000</value>
<description>zookeeper client ' ssession timeout. The client is disconnected, and as a result, all locksreleased, if a heartbeat isn't sent in thetimeout.</description& Gt
</property>

2) in Zoo.cfg:

#Limits the number of concurrent connections (at the socket level) that a singleclient, identified by IP address
maxclientcnxns=200
# The minimum session timeout into milliseconds that the server would allow Theclient to negotiate
minsessiontimeout=1000
# The maximum session timeout into milliseconds that the server would allow Theclient to negotiate
maxsessiontimeout=60000

From

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.