シングルまたは複数のURLに対して、時間までの時間を測定します。最も速く、最も遅い、中央値TTFB値を表示し、オプションですべての応答ヘッダーを記録できます。

Usage: ttfb [options] url [url...]
-d debug
-l <log file> (infers -d) log response headers. Defaults to ./curl.log
-n <number> of times to test time to first byte
-o <option> pass options to curl (e.g. -o "-k" will make curl ignore invalid certificates)
-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)
Curlの-Lオプションを使用して、リダイレクトチェーンに暗黙的に従います。
-dで呼び出して、すべての応答ヘッダー(デフォルトのログファイルは./curl.log )を記録できます。
-l /some/fileを指定して、デフォルトのログファイルをオーバーライドします。
URLを呼び出す回数を指定することにより、TTFB値が最も速く、最も遅く、中央値を取得します。 2つのテストに-n2に-n5使用します。
Calculation %{time_starttransfer¹} - %{time_appconnect²}を使用して、接続オーバーヘッドは含まれていません。
time_starttransfer
時間の数秒で、最初から最初のバイトが転送されようとしていたまでかかりました。これには、time_pretransferと、サーバーが結果を計算するために必要な時間も含まれます。
time_appconnect
時間が数秒で、最初からSSL/SSH/などがリモートホストに接続/ハンドシェイクが完了するまでかかりました。
https://github.com/sandeeprajuの要点に基づいています
[email protected]、@jaygoobyによって変更されました
マスターブランチからスクリプトをダウンロードして、実行可能にします。
curl -LJO https://raw.githubusercontent.com/jaygooby/ttfb.sh/master/ttfb
chmod +x ./ttfb
Usage: ttfb [options] url [url...]
-d debug
-l <log file> (infers -d) log response headers. Defaults to ./curl.log
-n <number> of times to test time to first byte
-o <option> pass options to curl (e.g. -o "-k" will make curl ignore invalid certificates)
-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)
基本的な使用法:
$ ttfb example.com
.227436
冗長応答の内訳による基本的な使用法:
$ ttfb -v https://example.com
DNS lookup: 0.005152 TLS handshake: 0.000000 TTFB including connection: 0.200831 TTFB: .200831 Total time: 0.201132
複数回テスト:
$ ttfb -n 5 example.com/example/url
.....
fastest .177263 slowest .214302 median .179957
複数のURLをテストします:
$ ttfb bbc.co.uk news.bbc.co.uk
bbc.co.uk .049985
news.bbc.co.uk .054122
複数のURLを複数回テストします。
$ ttfb -n 5 bbc.co.uk news.bbc.co.uk
.....
.....
bbc.co.uk fastest .030936 slowest .057755 median .034663
news.bbc.co.uk fastest .031413 slowest .182791 median .035001
複数のテストが指定されたときの冗長応答の内訳:
$ ttfb -v -n 5 bbc.co.uk
DNS lookup: 0.005335 TLS handshake: 0.102314 TTFB including connection: 0.148328 TTFB: .046014 Total time: 0.646115
DNS lookup: 0.005322 TLS handshake: 0.102609 TTFB including connection: 0.150693 TTFB: .048084 Total time: 0.644611
DNS lookup: 0.004277 TLS handshake: 0.102066 TTFB including connection: 0.172199 TTFB: .070133 Total time: 1.196256
DNS lookup: 0.004444 TLS handshake: 0.107375 TTFB including connection: 0.160771 TTFB: .053396 Total time: 0.637290
DNS lookup: 0.005352 TLS handshake: 0.118882 TTFB including connection: 0.168772 TTFB: .049890 Total time: 0.653761
fastest .046014 slowest .070133 median .049890
複数のURLへの複数のテストのすべての応答ヘッダーを記録します。
ttfb -d -n 2 bbc.co.uk https://www.bbc.co.uk/weather
..
..
bbc.co.uk fastest .027550 slowest .055215 median .041382
https://www.bbc.co.uk/weather fastest .101020 slowest .297923 median .199471
$ ls *.log
bbc_co_uk-curl.log https___www_bbc_co_uk_weather-curl.log
$ cat https___www_bbc_co_uk_weather-curl.log
HTTP/2 200
server: openresty
x-cache-action: MISS
vary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN
x-cache-age: 0
cache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate
content-type: text/html;charset=utf-8
x-mrid: w1
date: Thu, 11 Apr 2019 17:08:07 GMT
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-lb-nocache: true
x-msig: 24e37f81323984e4e45b8048f9e3c94a
x-frame-options: SAMEORIGIN
content-length: 1077454
HTTP/2 200
server: openresty
x-cache-action: MISS
vary: Accept-Encoding,X-BBC-Edge-Cache,X-BBC-Edge-Scheme,X-CDN
x-cache-age: 0
cache-control: private, stale-while-revalidate=10, max-age=0, must-revalidate
content-type: text/html;charset=utf-8
x-mrid: w1
date: Thu, 11 Apr 2019 17:08:08 GMT
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-lb-nocache: true
x-msig: 24e37f81323984e4e45b8048f9e3c94a
x-frame-options: SAMEORIGIN
content-length: 1077454
https://blog.cloudflare.com/a-question-of-timing/およびhttps://curl.haxx.se/docs/manpage.htmlを参照してください。
DevToolのTTFBのより良い近似を取得するために、接続オーバーヘッドのない時間を考慮します: %{time_starttransfer} - %{time_appconnect}
汚いevalを使用して、TTFB算術を行います。 bcおよびcolumnコマンドに依存します。
PRを提出したい場合は、既存のすべてのテストが合格し、新しい機能を追加する場合は、テストスイートにテストを追加してください。
テストを実行するには、プロジェクトルートからmakeを呼び出します。コウモリのコアをインストールし、 $PATHにインストールする必要があります。
テストを1つか2つしか実行しない場合は、気にしないテストの# skipラインを除外するため、 skipを読み、それらのテストがスキップされます。
詳細については、 CONTRIBUTING.mdを参照してください。
複数のリクエスト( -n 2など)オプションが設定されている場合の進行状況を表示します
-oオプションを使用してください) 複数のURLが提供されたときに最速のTTFBでソート出力
カラーコードTTFB:応答の速度に応じて、標準応答の数値。