最近遇到了需要在服务器上测试第三方api响应时间的需求。那么,怎么测呢?
curl安排上。
curl -w "dnslookup: %{time_namelookup} | connect: %{time_connect} | appconnect: %{time_appconnect} | pretransfer: %{time_pretransfer} | starttransfer: %{time_starttransfer} | total: %{time_total} | size: %{size_download}| redirect: %{time_redirect}"
比如: curl --location --request GET "https://www.tmall.com" -s -w %{http_code}:%{time_total}:%{speed_download}:%{time_namelookup}:%{time_redirect}:%{time_pretransfer}:%{time_appconnect}:%{time_starttransfer}:%{size_download}
那么,每个参数是什么意思呢,如下:
time_appconnect - The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.
time_connect - The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
time_namelookup - The time, in seconds, it took from the start until the name resolving was completed.
time_pretransfer - The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
time_redirect - The time, in seconds, it took for all redirection steps including name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections.
time_starttransfer - The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
time_total - The total time, in seconds, that the full operation lasted.
流程图如下:
如上图所示响应时间,如果有人问你,网络请求消耗了多长时间,那么time_pretransfer是不二之选!上图这种网络耗时2.259s,这是真慢!得治!