接口耗时怎么查

70 阅读1分钟

接口耗时耗在哪了?

zhuanlan.zhihu.com/p/609213747

首先要知道的是接口的完整链路,如下图所示,

image.png

然后通过 curl 来检查每个过程的耗时

curl -Lo /dev/null -skw "time_namelookup: %{time_namelookup} s\ntime_connect: %{time_connect} s\ntime_appconnect: %{time_appconnect} s\ntime_pretransfer: %{time_pretransfer} s\ntime_starttransfer: %{time_starttransfer} s\ntime_redirect: %{time_redirect} s\nspeed_download: %{speed_download} B/s\ntime_total: %{time_total} s\n\n"  'https://baidu.com'

打印结果如下

image.png

然后就可以参考对比查看耗时的节点,排查修复具体节点的问题。