linux下使用curl分析http请求耗时
curl命令可以用来进行分析http请求的各个阶段耗时,有时候会用来分析后端响应是不是有些慢。
一个简单的例子:
curl -o /dev/null -s -w %{http_code}:%{time_namelookup}:%{time_redirect}:%{time_pretransfer}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} www.baidu.com
对里面的一些字段做下记录:
http_code: http状态码,如200成功,301转向,404未找到,500服务器错误等。
time_total 总时间,按秒计。
time_namelookup DNS解析时间,从请求开始到DNS解析完毕所用时间。
time_connect 连接时间,从开始到建立TCP连接完成所用时间,包括前边DNS解析时间,如果需要单纯的得到连接时间,用这个time_connect时间减去前边time_namelookup时间。
time_appconnect 连接建立完成时间,如SSL/SSH等建立连接或者完成三次握手时间。
time_pretransfer 从开始到准备传输的时间。
time_redirect 重定向时间,包括到最后一次传输前的几次重定向的DNS解析,连接,预传输,传输时间。
curl -w "@curl-format.txt" -o /dev/null -s -L "https://www.baidu.com”
cat curl-format.txt
http: %{http_code}\n
dns: %{time_namelookup}s\n
redirect: %{time_redirect}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_starttransfer: %{time_starttransfer}s\n
——————:\n
time_total: %{time_total}s\n
浙公网安备 33010602011771号