日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用CURL检测Clinet侧发起的HTTP请求各阶段时间

發布時間:2023/12/31 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用CURL检测Clinet侧发起的HTTP请求各阶段时间 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

第一、HTTP請求的過程介紹

一個HTTP請求,涉及多個階段

1、DNS解析域名

2、請求從Clinet路由至Server,Clinet與Server建立TCP連接

3、如果使用了HTTPS,還涉及SSL連接的建立

4、server開始準備數據

開始邏輯計算、調后端接口、查數據庫緩存等

5、server開始傳遞數據

數據準備完成,開始給client傳數據

6、數據傳輸完畢

7、整個過程可能還涉及多次重定向

?

?

第二、關于CURL的介紹

CURL是利用URL語法在命令行方式下工作的開源數據傳輸工具。

支持:DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling 等

最新版的curl穩定版為7.55.1(截止20170817)

源代碼:https://github.com/curl/curl

?

?

?

第三:用CURL檢測Clinet側發起的HTTP請求各階段時間,簡要說明

1、TCP建立連接的耗時:CONNECT-NAMELOOKUP

2、建立TCP連接到server返回client第一個字節的時間:

STARTTRANSFER-CONNECT

3、SERVER處理數據的時間:

可以用STARTTRANSFER - PRETRANSFER計算得到

4、CLIENT接收數據的耗時(開始接收至接收完成):

TOTAL-STARTTRANSFER

?

?

第四、例子:

curl -o /dev/null -s -w time_namelookup:"\t"%{time_namelookup}"\n"time_connect:"\t\t"%{time_connect}"\n"time_appconnect:"\t"%{time_appconnect}"\n"time_pretransfer:"\t"%{time_pretransfer}"\n"time_starttransfer:"\t"%{time_starttransfer}"\n"time_total:"\t\t"%{time_total}"\n"time_redirect:"\t\t"%{time_redirect}"\n" ?https://www.yqb.com/

1、DNS解析耗時:0.008s

2、TCP建立連接的耗時:0.059-0.008=0.051s

3、SSL握手完成耗時:0.228-0.059=0.169s

169ms,多了一層SSL還是很耗時的

4、server處理數據的時間:0.287-0.228=0.059

59ms,說明服務器處理很快

5、總體的耗時:0.228s

6、整個過程沒有redirect,所以redirect的耗時為0

?

?

再舉一例:

服務器處理數據的耗時:2.305-0.014=2.291s

這就說明server端的性能是值得研究的。

對于server端而言,有需要分析它的耗時:

防火墻->負載均衡->應用->緩存和DB

需要深入去分析這個時間消耗在哪個環節,有針對性的優化。

?

?

?

第五、詳細說明

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

CURLINFO_REDIRECT_TIME. The time it took for all redirection steps include name lookup, connect, pretransfer and transfer before final transaction was started. So, this is zero if no redirection took place.

另:python也有一個pycurl模塊,大家可以嘗試。


?

參考:

https://curl.haxx.se/libcurl/c/curl_easy_getinfo.html

轉載于:https://my.oschina.net/u/3656540/blog/2986659

總結

以上是生活随笔為你收集整理的使用CURL检测Clinet侧发起的HTTP请求各阶段时间的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。