Jon’s recent Find the Time to First Byte Using Curl post reminded me about the additional timing details that cURL can provide. cURL supports formatted output for the details of the request ( see the cURL manpage for details, under “-w, –write-out ” ). For our purposes we’ll focus just on the timing details that are provided. Step one: create a new file, curl-format.txt, and paste in: time_namelookup: %{time_namelookup} time_connect: %{time_connect} time_appconnect: %{time_appconnect} time_pretr.... 有更新! Timing Details With cURL curl
前言 上周,我方的一个客户反馈,访问我们的接口,平均耗时在2s以上。但是我方对请求进入,和请求返回,整个过程都有监控,我方的耗时基本在50ms以内,非常快。 后来了解到,客户从广东访问到我方上海,公网来访问我方。那么就建议去检测,DNS耗时,TCP建立的耗时等。理论上,长距离的公网,网络延迟就非常高。遂建议使用CURL去检查。结果果然如猜想,在TCP建立的耗时就很久。 进入正题,这篇文章主要介绍使用CURL检测Client端发起的HTTP请求,各个阶段的时间。 第一、HTTP请求的过程介绍 一个HTTP请求,涉及多个阶段 DNS解析域名 请求从Clinet路由至Server,Clinet与Server建立TCP连接 如果使用了HTTPS,还涉及SSL连接的建立 server开始准备数据 开始逻辑计算、调后端接口、查数据库缓存等 server开始传递数据 数据准备完成,开始给client传数据 数据传输完毕 整个过程可能还涉及多次重定向 第二、关于CURL的介绍 CURL是利用URL语法在命令行方式下工作的开源数据传输工具。 支持:DICT, FILE, FTP, FTPS,.... 有更新! 使用CURL检测Clinet侧发起的HTTP请求各阶段时间 curl