性能文章>TPS分析优化案例>

TPS分析优化案例原创

3周前
199102
概述
对Nginx域名转发做了个压测,结果不大理想,jmeter哗哗的报错,Nginx连接全是超时,tps波动剧烈,如下图
tps在490的时候开始剧烈抖动
大致的错误信息如下

{ : "timestamp":"2021-09-22T07:52:22.178+0000", : "status":500, : "error":"Internal Server Error", : "message":"\n### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure\n\nThe last packet successfully received from the server was 10,949 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.\n### The error may exist in class path resource [mybatis/mapper/UserMapper.xml]\n### The error may involve defaultParameterMap\n### The error occurred while setting parameters\n### SQL: SELECT user_id,user_name,user_nickname,user_password,user_realname,user_gender,user_birthday,user_profile_picture_src,user_address,user_homeplace FROM user WHERE user_name = ? and user_password = ?\n### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure\n\nThe last packet successfully received from the server was 10,949 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.\n; Communications link failure\n\nThe last packet successfully received from the server was 10,949 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure\n\nThe last packet successfully received from the server was 10,949 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.", : "path":"/tmall/login/doLogin" }

 
看错误信息是因为jdbc连接池异常中断导致的,检查一下连接池的配置

 

考虑到系统使用的人很少,几乎不会有多少jdbc并发,所以连接池的最大连接数有点高了,可能会资源浪费。改小一点再做调试

 

spring.datasource.druid.initial-size=3

spring.datasource.druid.min-idle=3

spring.datasource.druid.max-active=10 

 

Tps基本保持稳定,jmeter不再报错。但是偶尔还是会有波动

 

linux能看到一些错误信息,如下 

 

  •  
  •  
  •  
  •  
The last packet successfully received from the server was 11,938 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 11,938 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.] with root cause java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3014) ~[mysql-connector-java-5.1.47.jar:5.1.47] at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3472) ~[mysql-connector-java-5.1.47.jar:5.1.47] at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3462) ~[mysql-connector-java-5.1.47.jar:5.1.47] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3905) ~[mysql-connector-java-5.1.47.jar:5.1.47] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530) ~[mysql-connector-java-5.1.47.jar:5.1.47] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683) ~[mysql-connector-java-5.1.47.jar:5.1.47] at

 

调用login方法的时候,mysql的IO队列阻塞了,数据包回不来。直接检查login调用的user表,看索引。 这张表里面对username加了索引,但是没有对password加,也没对realname加。实际上登录执行的是realname字段!

 

把索引补上再次运行,tps稳定不抖动,后端无任何错误信息 

 

 

应用和数据库分离

 

先那个mysql应用和项目应用是在同一台服务器上面。后期调试的时候直接把mysql应用拉到了另一台服务器上。再次执行发现tps能够稳定在到800左右,无任何异常。 

 

 

 

点赞收藏
飞天小子

13软件测试,10年性能测试,5年性能培训,10万字性能博主,惠普中国项目经理,微信uhz2008

请先登录,感受更多精彩内容
快去登录吧,你将获得
  • 浏览更多精彩评论
  • 和开发者讨论交流,共同进步

为你推荐

保证接口数据安全的10种方案

保证接口数据安全的10种方案

这样优化Spring Boot,启动速度快到飞起!

这样优化Spring Boot,启动速度快到飞起!

接口流量突增,如何做好性能优化?

接口流量突增,如何做好性能优化?

能ping通,TCP就一定能连通吗?

能ping通,TCP就一定能连通吗?

Mysql服务器线程阻塞分析

Mysql服务器线程阻塞分析

集群节点宕机问题排查

集群节点宕机问题排查

2
0