cURL で取得できるレスポンスタイムの内訳

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2016/10)です。
※ 情報が古い可能性もありますので、ご留意ください。



cURL で取得できるレスポンスタイムの内訳について、引用的なメモ。

Step 4: Print timing breakdown

But we still don’t see the timing breakdown of the HTTP request as promised. If we go through all the options supported by curl (http://curl.haxx.se/docs/manpage.html) we will see that it has the capability of returning timing information on the hostname lookup ( time_namelookup), the time it takes to connect to the remote host ( time_connect), the time it takes to start transferring data ( time_pretrasnfer), the total time ( total_time) and many others. In order to display this information on our console in a pretty and human readable format copy and paste the following command:

$ curl -L --output /dev/null --silent --show-error --write-out 'lookup:        %{time_namelookup}\nconnect:       %{time_connect}\nappconnect:    %{time_appconnect}\npretransfer:   %{time_pretransfer}\nredirect:      %{time_redirect}\nstarttransfer: %{time_starttransfer}\ntotal:         %{time_total}\n' 'google.com'
 lookup:        0.036
 connect:       0.053
 appconnect:    0.000
 pretransfer:   0.053
 redirect:      0.105
 starttransfer: 0.118
 total:         0.253


appconnect is the time, in seconds, it took from the start until the SSL/SSH/etc. connect/handshake to the remote host was completed. In the example above it is zero because we don’t use the HTTPS protocol. If you try the same command with “https://google.com” you get the following nonzero value for appconnect:

$ curl -L –output /dev/null –silent –show-error –write-out ‘lookup:        %{time_namelookup}\nconnect:       %{time_connect}\nappconnect:    %{time_appconnect}\npretransfer:   %{time_pretransfer}\nredirect:      %{time_redirect}\nstarttransfer: %{time_starttransfer}\ntotal:         %{time_total}\n’ ‘https://google.com’
lookup:        0.038
connect:       0.063
appconnect:    0.177
pretransfer:   0.178
redirect:      0.225
starttransfer: 0.679
total:         0.929
HTTP Transaction Timing with Curl | NetBeez Network Monitoring

各値 (内訳) に関する詳細説明

  • lookup: 開始から名前の解決が完了するまでにかかった時間(秒単位)。
  • connect: 開始からリモートホスト(またはプロキシ)へのTCP接続が完了するまでにかかった時間(秒単位)。
  • appconnect: 開始からリモートホストへのSSL / SSH / などの接続 / ハンドシェイクが完了するまでにかかった時間(秒単位)。 (7.19.0で追加)
  • pretransfer: 開始からファイル転送が開始されるまでにかかった時間(秒単位)。これには、関連する特定のプロトコルに固有のすべての転送前コマンドとネゴシエーションが含まれます。
  • redirect: 最後のトランザクションが開始されるまでに、名前の検索、接続、事前転送、転送を含むすべてのリダイレクト手順にかかった時間(秒単位)。 time_redirectは、複数のリダイレクトの完全な実行時間を示します。 (7.12.3で追加)
  • starttransfer: 開始から最初のバイトがちょうど転送されるまでにかかった時間(秒単位)。これには、time_pretransferと、サーバーが結果を計算するために必要な時間も含まれます。
  • total: 完全な操作が継続した合計時間(秒単位)。時刻はミリ秒単位で表示されます。

Here is what each value represents, according to curl’s manual page:

  • lookup: The time, in seconds, it took from the start until the name resolving was completed.
  • connect: The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
  • appconnect: The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed. (Added in 7.19.0)
  • pretransfer: The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
  • redirect: The time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3)
  • starttransfer: The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
  • total: The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.
HTTP Transaction Timing with Curl | NetBeez Network Monitoring