zoukankan      html  css  js  c++  java
  • 使用curl命令分析http请求耗时情况

    使用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 
    
    
    
             http_code:  %{http_code}
    
            local_addr:  %{local_ip}:%{local_port}
    
           remote_addr:  %{remote_ip}:%{remote_port}
    
           size_upload:  %{size_upload}
    
          speed_upload:  %{speed_upload}
    
         size_download:  %{size_download}
    
        speed_download:  %{speed_download}
    
                       ----------
    
       time_namelookup:  %{time_namelookup}
    
          time_connect:  %{time_connect}
    
       time_appconnect:  %{time_appconnect}
    
         time_redirect:  %{time_redirect}
    
      time_pretransfer:  %{time_pretransfer}
    
    time_starttransfer:  %{time_starttransfer}
    
                       ----------
    
            time_total:  %{time_total}
    
    [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 

  • 相关阅读:
    Spring Cloud 企业云服务架构common-service代码分析
    Spring Cloud云服务架构代码结构构建
    配置环境真是复杂的事情
    一起来关注c11 吧!!!
    utubu
    今天开放了这个居然
    编译linux程序,unistd.h vc的处理
    postgres 设置密码
    提供各种开源软件编译服务的想法
    CSS基础
  • 原文地址:https://www.cnblogs.com/standby/p/14299844.html
Copyright © 2011-2022 走看看