1. 准備文件模版(curl.txt)
\n time_namelookup: %{time_namelookup}\n time_connect: %{time_connect}\n time_appconnect: %{time_appconnect}\n time_pretransfer: %{time_pretransfer}\n time_redirect: %{time_redirect}\n time_starttransfer: %{time_starttransfer}\n ----------\n time_total: %{time_total}\n \n
2. 使用curl帶以下參數請求
curl -w "@curl.txt" -o /dev/null -s https://www.sogo.com
結果:
[@ ~]# curl -w "@curl" -o /dev/null -s https://www.sogo.com time_namelookup: 0.004 time_connect: 0.014 time_appconnect: 0.141 time_pretransfer: 0.141 time_redirect: 0.000 time_starttransfer: 0.153 ---------- time_total: 0.165
NAMELOOKUP:從開始計算,域名解析完成的耗時
CURLINFO_NAMELOOKUP_TIME. The time it took from the start until the name resolving was completed.
CONNECT:從開始計算,TCP建立完成的耗時
CURLINFO_CONNECT_TIME. The time it took from the start until the connect to the remote host (or proxy) was completed.
APPCONNECT:從開始計算,應用層(SSL,在TCP之上的應用層)連接/握手完成的耗時
CURLINFO_APPCONNECT_TIME. The time it took from the start until the SSL connect/handshake with the remote host was completed. (Added in in 7.19.0)
PRETRANSFER:從開始計算,准備開始傳輸數據的耗時
CURLINFO_PRETRANSFER_TIME. The time it took from the start until the file transfer is just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
STARTTRANSFER:從開始計算,開始傳輸數據的耗時(libcurl接收到第一個字節)
CURLINFO_STARTTRANSFER_TIME. The time it took from the start until the first byte is received by libcurl.
TOTAL:總的耗時
CURLINFO_TOTAL_TIME. Total time of the previous request.
REDIRECT:整個過程重定向的耗時,如果整個過程沒有重定向,這個時間為0
舉個實際的例子吧。 工作中有人反映,我們有個頁面打開的非常慢,需要1份多鍾。
進入我們自己服務的docker容器, curl -v -w "@curl.txt" -o /dev/null -s 127.0.0.1:/xxx/xxx/x。發現時間主要在time_starttransfer之后,也就是time_total - time_starttransfer占了整個請求的大部分時間。
這也就基本定位是微服務自身的問題。 看日志,在讀取文件列表時非常慢。
使用time ls -l和time tar -zxvf ***.tar.gz 和linux的dd命令發現文件讀寫非常慢。time 加到linux命令前,可以查看命令的執行時間。
聯系持久卷nfs的同事,微小的網絡延遲都會導致nfs讀取速度很慢。這也是帶延遲測試場景,實際場景中有延遲時要先解決延遲的問題。