Read more

Measure HTTP Connection times (TTFB) with curl

Avatar
Kim Klotz
December 21, 2022Software engineer at makandra GmbH

To measure the time of your HTTP request with curl, you can use the -w (--write-out) option:

curl --silent -o /dev/null -w "%{time_connect};%{time_starttransfer};%{time_total};%{time_appconnect};%{time_pretransfer}\n" https://example.org
0.121080;0.685826;0.685881;0.571310;0.571396
Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

With -w you can make curl display informations for your HTTP request. As seen in the example above you can e.g. output this in a CSV format for further analysis.

Informations to the specific informations can be found in the man page Show archive.org snapshot :

[...]
              time_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)

              time_connect   The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.

              time_namelookup
                             The time, in seconds, it took from the start until the name resolving was completed.

              time_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.

              time_redirect  The  time,  in  seconds,  it took for all redirection steps including 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)

              time_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.

              time_total     The total time, in seconds, that the full operation lasted.
[...]
Posted by Kim Klotz to makandra Operations (2022-12-21 09:22)