Webseiten Timings mit cUrl messen

Wer kennt es nicht. Bei Webseiten ist man immer und immer wieder am optimieren, um seinen Seiteninhalt schnellst möglich auszuliefern...

Allerdings ist das nicht immer so einfach. Klar kann man innerhalb seiner Seite Programmatische Messungen durchführen. Aber es geht auch anders!

Das Zaubertool an dieser Stelle ist cUrl.
Ja, richtig gelesen. cUrl untersütz nämlich Ausgabeformate, mit sämtlichen Details zum HTTP/S Request. Um diese Funktion zu benutzen brauchen wir den -w Paramater. -w nimmt als Option das Ausgabeformation in Form eines Strings oder alternativ in form einer Datei an.

Hier nun ein Beispiel mit einem Format String:

  1. curl -w "Verbindung: %{time_connect} TTF: %{time_starttransfer} Gesamt: %{time_total} \n" -o /dev/null it.cjunky.de

Die Ausgabe sieht dann wie folgt aus:

  1. Verbindung: 0.000 TTF: 0.008 Gesamt: 0.008

Bei der anderen Variante müssen wir erst ein wenig Vorarbeit leisten.
Zuerst legen wir das Format File an. In meinem Fall habe ich die Datei "curl-format-timings.txt" genannt.
Der Inhalt sieht wie folgt aus:

  1. \n
  2. time_namelookup: %{time_namelookup}\n
  3. time_connect: %{time_connect}\n
  4. time_appconnect: %{time_appconnect}\n
  5. time_pretransfer: %{time_pretransfer}\n
  6. time_redirect: %{time_redirect}\n
  7. time_starttransfer: %{time_starttransfer}\n
  8. -------------------------------\n
  9. time_total: %{time_total}\n
  10. \n

Nachdem wir das Format festgelegt haben, machen wir nun HTTP/S Reqeust

curl -w "@curl-format-timings.txt" -o /dev/null -s it.cjunky.de

  1. time_namelookup: 0.004
  2. time_connect: 0.004
  3. time_appconnect: 0.000
  4. time_pretransfer: 0.004
  5. time_redirect: 0.000
  6. time_starttransfer: 0.043
  7. -------------------------------
  8. time_total: 0.043

Wie man nun sieht, hab ich den -w Parameter mit "@curl-format-timings.txt" versehen. Das @ sagt cUrl das eine Datei anstelle eines Strings verwendet werden soll.

Es gibt natürlich noch weitere Variablen die in der Ausgabe Verwendet Werden können.
Hier ein paar Variablen direkt aus der cUrl Man Page.

content_type
The Content-Type of the requested document, if there was any.
filename_effective
The ultimate filename that curl writes out to. This is only meaningful if curl is told to write to a file with the --remote-name or --output option. It's most useful in combination with the --remote-header-name option. (Added in 7.26.0)
ftp_entry_path
The initial path curl ended up in when logging on to the remote FTP server. (Added in 7.15.4)
http_code
The numerical response code that was found in the last retrieved HTTP(S) or FTP(s) transfer. In 7.18.2 the alias response_code was added to show the same info.
http_connect
The numerical code that was found in the last response (from a proxy) to a curl CONNECT request. (Added in 7.12.4)
http_version
The http version that was effectively used. (Added in 7.50.0)
local_ip
The IP address of the local end of the most recently done connection - can be either IPv4 or IPv6 (Added in 7.29.0)
local_port
The local port number of the most recently done connection (Added in 7.29.0)
num_connects
Number of new connects made in the recent transfer. (Added in 7.12.3)
num_redirects
Number of redirects that were followed in the request. (Added in 7.12.3)
redirect_url
When an HTTP request was made without -L to follow redirects, this variable will show the actual URL a redirect would take you to. (Added in 7.18.2)
remote_ip
The remote IP address of the most recently done connection - can be either IPv4 or IPv6 (Added in 7.29.0)
remote_port
The remote port number of the most recently done connection (Added in 7.29.0)
size_download
The total amount of bytes that were downloaded.
size_header
The total amount of bytes of the downloaded headers.
size_request
The total amount of bytes that were sent in the HTTP request.
size_upload
The total amount of bytes that were uploaded.
speed_download
The average download speed that curl measured for the complete download. Bytes per second.
speed_upload
The average upload speed that curl measured for the complete upload. Bytes per second.
ssl_verify_result
The result of the SSL peer certificate verification that was requested. 0 means the verification was successful. (Added in 7.19.0)
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 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)
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. The time will be displayed with millisecond resolution.
url_effective
The URL that was fetched last. This is most meaningful if you've told curl to follow location: headers.

Die Timings so zu messen bringt einen schon erheblich weiter.
Allerdings ist man ab einem bestimmten Punkt darauf angewiesen die Messungen innerhalb seines Codes durchzuführen, da man mit der cUrl Variante keinen einblick in die internen Abläufe bekommt...

Neuen Kommentar schreiben