Communications link failure问题解决方案摸索

性能测试发现了Communications link failure错误,搜寻了网络上的好多种解决方案,记录总结一下。

错误信息

Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

在低并发下400个链接没有问题,一旦上了500就会报错,1000并发之后错误是肯定会发生。怀疑可能是并发太高了导致的,顺着这个找资料:
网上教的提高timeout时间,修改localhost都不可行,我的数据库中间有负载均衡器,空闲时间10分钟内,比较短。

排查方向,Mysql版本驱动–尽量和数据库保持一致。

注释skip-networking

后查看网络资料mysql配置中skip-networking未注释,参数skip-networking起的作用是:mysql不再在TCP / IP端口上进行监听,与mysqld的所有互动都必须通过Unix套接字或命名管道进行。

配置文件注释如下

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!

将参数skip-networking注释重启mysql服务,jdbc程序连接mysql正常。
————————————————
版权声明:本文为CSDN博主「cktmyh」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cktmyh/article/details/53727386

以下来自stackoverflow

CommunicationsException: Communications link failure

If you get a SQLException: Connection refused or Connection timed out or a MySQL specific CommunicationsException: Communications link failure, then it means that the DB isn't reachable at all. This can have one or more of the following causes:

IP address or hostname in JDBC URL is wrong.
Hostname in JDBC URL is not recognized by local DNS server.
Port number is missing or wrong in JDBC URL.
DB server is down.
DB server doesn't accept TCP/IP connections.
DB server has run out of connections.
Something in between Java and DB is blocking connections, e.g. a firewall or proxy.

To solve the one or the other, follow the following advices:

Verify and test them with ping.
Refresh DNS or use IP address in JDBC URL instead.
Verify it based on my.cnf of MySQL DB.
Start the DB.
Verify if mysqld is started without the --skip-networking option.
Restart the DB and fix your code accordingly that it closes connections in finally.
Disable firewall and/or configure firewall/proxy to allow/forward the port.

网络带宽引发

将千兆网络换成万兆网络。(问题不再发生,但是具体原因还没有找出来)

Haproxy版本问题

将Haproxy版本从1.5升级到2.1,可能性比较低。(没有任何关系)

添加skip-name-resolve

Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. 问题的另一个解决方式

很多的解决对策都是修改wait_timeout和interactive_timeout;
但是我的这样没有解决;
死磕了半天时间,终于解决了:直接写出结果吧!

去看mysql的errorlog,看到类似如下的信息:

Forcing close of thread xxxxx user: ‘root’

发现这算属MySQL的一个bug,不管连接是通过hosts还是ip的方式,MySQL都会对DNS做反查,IP到DNS,由于反查的接续速度过慢(不管是不是isp提供的dns服务器的问题或者其他原因),大量的查询就难以应付,线程不够用就使劲增加线程,但是却得不到释放,所以MySQL会“ 假死”。
---- 这个是不是能解释为什么设置为localhost也能解决这个问题???? 其实就是并发太高处理有问题。
解决的方案很简单,结束这个反查的过程,禁止任何解析。

1、打开mysql的配置文件(my.cnf),在[mysqld]下面增加一行:

skip-name-resolve

2、在my.ini添加的内容:

skip-name-resolve
————————————————
版权声明:本文为CSDN博主「Martin哒哒啦,让16变的难忘」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43621487/article/details/103712728
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值