ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用curl命令分析http请求耗时情况

2021-01-19 20:33:32  阅读:284  来源: 互联网

标签:http upload 耗时 time download curl speed size


使用curl命令发送http POST请求

curl -v -X POST -d @data.json --header "Content-Type: application/json" $url

curl -w选项

Defines what to display on stdout after a completed and successful operation. 
The format is a string that may contain plain text mixed with any number of variables. The string can be specified as "string", to get read from a particular file you specify it "@filename"
and to tell curl to read the format from stdin you write "@-".

 示例

[root@localhost ~]# cat format.txt 
\n\n
         http_code:  %{http_code}\n
        local_addr:  %{local_ip}:%{local_port}\n
       remote_addr:  %{remote_ip}:%{remote_port}\n
       size_upload:  %{size_upload}\n
      speed_upload:  %{speed_upload}\n
     size_download:  %{size_download}\n
    speed_download:  %{speed_download}\n
                   ----------\n
   time_namelookup:  %{time_namelookup}\n
      time_connect:  %{time_connect}\n
   time_appconnect:  %{time_appconnect}\n
     time_redirect:  %{time_redirect}\n
  time_pretransfer:  %{time_pretransfer}\n
time_starttransfer:  %{time_starttransfer}\n
                   ----------\n
        time_total:  %{time_total}\n
[root@localhost ~]# 
[root@localhost ~]# curl -v -w @format.txt -X POST -d @data.json --header "Content-Type: application/json" $url
* About to connect() to v.qq.com port 80 (#0)
*   Trying 8.8.8.8...
* Connected to v.qq.com (8.8.8.8) port 80 (#0)
> POST /api/v2/database/upload?name=ron&age=18 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: v.qq.com
> Accept: */*
> Content-Type: application/json
> Content-Length: 717
> 
* upload completely sent off: 717 out of 717 bytes
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 19 Jan 2021 11:58:31 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 145
< Connection: keep-alive
< 
* Connection #0 to host v.qq.com left intact
{"code":200,"data":{"download_url":"","download_protocol":"","host":"","intra_host":"","name":"","version":"","size":0,"image_id":""},"msg":"ok"}

         http_code:  200
        local_addr:  10.0.0.9:32155
       remote_addr:  8.8.8.8:80
       size_upload:  717         // The total amount of bytes that were uploaded.
      speed_upload:  67.000      // The average upload speed that curl measured for the complete upload. Bytes per second.
     size_download:  145         // The total amount of bytes that were downloaded.
    speed_download:  13.000      // The average download speed that curl measured for the complete download. Bytes per second.
                   ----------
   time_namelookup:  10.523      // 从开始到完成域名解析的耗时
      time_connect:  10.548      // 从开始到完成TCP三次握手的耗时
   time_appconnect:  0.000       // 从开始到完成ssl/ssh等上层协议建立的耗时
     time_redirect:  0.000       // 
  time_pretransfer:  10.549      // 从请求开始到响应开始传输的时间
time_starttransfer:  10.642      // 从请求开始到第一个字节将要传输的时间,即Time To First Byte (TTFB) 
                   ----------
        time_total:  10.643
[root@localhost ~]# 

各变量对应的时间点详见下图

 

更多参考:A Question of Timing 

标签:http,upload,耗时,time,download,curl,speed,size
来源: https://www.cnblogs.com/standby/p/14299844.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有