接口响应时间长问题排查流程

当一个接口响应时间非常长时,如何定位问题并解决?

1、先拿到curl。浏览器netWork --> copy as curl 如果是app则抓包下,copy出来.如下:

curl -H 'Host: xxxxxx.com' -H 'Cookie: uid=CgoUFF/J3UVXIkMEB0//Ag==' -H 'apptype: 3' -H 'user-agent: ling zhi wen zhen ce shi/2.1.2 (iPhone; iOS 14.0; Scale/2.00)' -H 'storeid: ' -H 'deviceuuid: 6E47AC24-5477-4CB3-9E97-F0689776DFBA' -H 'accountid: 1293541453032587288' -H 'appversion: 2.1.2' -H 'client: ios' -H 'version: 2.1.2' -H 'usertype: GROUPUSER' -H 'sign: 89BEE7049DF61EFFFBA226AE076023F9' -H 'token: 9a2123abccbee8fcee1d0265a4bb3d44' -H 'timestamp: 1608776144395' -H 'accept-language: en;q=1' -H 'accept: */*' -H 'content-type: application/json;charset=utf-8' -H 'appver: 3' --data-binary '{"token":"9a2123abccbee8fcee1d0265a4bb3d44","organSign":"ZHL0009529","activityType":1}' --compressed 'https://xxxxx.com/patient/rights/verify'

2、curl 改造。在curl和-H前加入:

 "\ntime_namelookup: "%{time_namelookup}"\ntime_connect: "%{time_connect}"\ntime_appconnect: "%{time_appconnect}"\ntime_pretransfer: "%{time_pretransfer}"\ntime_starttransfer: "%{time_starttransfer}"\ntime_redirect: "%{time_redirect}"\ntime_total: "%{time_total}"\n"

3、改造后的curl如下:

curl -w  "\ntime_namelookup: "%{time_namelookup}"\ntime_connect: "%{time_connect}"\ntime_appconnect: "%{time_appconnect}"\ntime_pretransfer: "%{time_pretransfer}"\ntime_starttransfer: "%{time_starttransfer}"\ntime_redirect: "%{time_redirect}"\ntime_total: "%{time_total}"\n"  -H 'Host: xxx.com' -H 'Cookie: uid=CgoUFF/J3UVXIkMEB0//Ag==' -H 'apptype: 3' -H 'user-agent: ling zhi wen zhen ce shi/2.1.2 (iPhone; iOS 14.0; Scale/2.00)' -H 'storeid: ' -H 'deviceuuid: 6E47AC24-5477-4CB3-9E97-F0689776DFBA' -H 'accountid: 1293541453032587288' -H 'appversion: 2.1.2' -H 'client: ios' -H 'version: 2.1.2' -H 'usertype: GROUPUSER' -H 'sign: 89BEE7049DF61EFFFBA226AE076023F9' -H 'token: 9a2123abccbee8fcee1d0265a4bb3d44' -H 'timestamp: 1608776144395' -H 'accept-language: en;q=1' -H 'accept: */*' -H 'content-type: application/json;charset=utf-8' -H 'appver: 3' --data-binary '{"token":"9a2123abccbee8fcee1d0265a4bb3d44","organSign":"ZHL0009529","activityType":1}' --compressed 'https://xxxxxx.com/patient/rights/verify'

4、执行curl。结果如下:

time_namelookup: 0.253
time_connect: 0.257
time_appconnect: 0.361
time_pretransfer: 0.361
time_starttransfer: 5.618
time_redirect: 0.000
time_total: 5.618

5、相关含义如下:

参数

含义

  

time_namelookup

DNS解析域名时间

  

time_connect

TCP连接的时间,三次握手的时间

  

time_starttransfer

从请求开始到第一个字节将要传输的时间

  

time_total

总时间

  

speed_download

下载速度,单位-字节每秒

  

time_appconnect

SSL|SSH等上层连接建立的时间

  

time_pretransfer

从请求开始到响应开始传输的时间

  

time_redirect

从开始到最后一个请求事务的时间

6、如果时间大部分是time_starttransfer 减去time_pretransfer的值。则代表此请求慢的原因在服务器业务代码执行部分。

7、业务代码耗时代码快定位。使用arthas排查即可。

8、启动arthas.

java -jar arthas-boot.jar

9、选择Java进程。输入序号。

10、执行 类全名 + 方法名

trace com.xxxx.service.impl.xxxxServiceImpl xxxMethod

11、查看耗时调用。

猜你喜欢

转载自blog.csdn.net/MrBack/article/details/111624376