Calculating Server Processing Time With Curl

2019-02-08 05:17发布

I am getting request timing info with curl using the --write-out option as described in this article.

Here is example output from one of my requests:

        time_namelookup:  0.031
           time_connect:  0.328
        time_appconnect:  1.560
       time_pretransfer:  1.560
          time_redirect:  0.000
     time_starttransfer:  1.903
                        ----------
             time_total:  2.075

My question is: How can I determine how much time the server took processing the request? Is the answer:

time_starttransfer - time-connect

That is, the time from when the connection was established to when the server starting sending its response? That seems correct but I want to be sure.

Details about curl timing variables may be found here: http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html

标签: http curl
2条回答
萌系小妹纸
2楼-- · 2019-02-08 06:04

I'd say that you're right, (time_starttransfer - time_connect) definitely is an amount of time server took to process the request.

However - I also wondered what is the difference between time_connect and time_pretransfer? (intrigued by @Schwartzie and @Cheeso comments)

By looking at several curl queries on the web I observed that sometimes they're equal and sometimes they're not.

Then I figured out (at least I believe so) that they differ only for HTTPS requests, cause server needs some time to decrypt ssl layer, which is not exactly the time spent by the target app but the time spent by server hosting the app/service.

The time to decrypt ssl (and to connect also, the one given in time_connect) is time_appconnect, and only when it's 0 (like for non-https requests) - time_connect and time_pretransfer are EQUAL, otherwise for https requests they differ, and for https time_pretransfer would be equal to time_appconnect (and not to time_connect).

Check the following two examples:

  • curl -kso /dev/null -w "time_connect=%{time_connect}, time_appconnect:%{time_appconnect}, time_pretransfer=%{time_pretransfer}\n" http://www.csh.rit.edu

    • time_connect=0.128, time_appconnect:0.000, time_pretransfer=0.128
  • curl -kso /dev/null -w "time_connect=%{time_connect}, time_appconnect:%{time_appconnect}, time_pretransfer=%{time_pretransfer}\n" https://www.csh.rit.edu

    • time_connect=0.133, time_appconnect:0.577, time_pretransfer=0.577

so I'd say that time_pretransfer is more precise to be used compared to time_connect since it'll respect ssl connections too, and maybe some other things I'm not aware of.

With all the previous being said, I'd say that more precise answer for the question:

  • "How can I determine how much time the server took processing the request?"

would probably be:

  • time_starttransfer - time_pretransfer

as @Schwartzie already mentioned, I just wanted to understand why.

查看更多
Evening l夕情丶
3楼-- · 2019-02-08 06:12

Yes, (time_starttransfer - time-connect) is the time from the connect was noticed by curl until the first byte arrived. Do note that it also includes the transfer time so for a remote site it will be longer simply because of that.

查看更多
登录 后发表回答