curlコマンドを使って、Webサーバやネットワークの性能計測(ダウンロード・アップロードの秒あたりの平均バイト数等)を行う †curlコマンドによるWebサーバやネットワークの性能測定方法例を以下に記します。 関連資料 †curlコマンドの基本的な利用方法 †curlコマンドはコマンドラインでのhttpクライアントとして、 利用方法は以下のようにコマンドの引数にURLを指定するだけです。 % curl http://www.example.tld/file/test.txt このままですと、/file/test.txtの内容は標準出力、つまり端末の場面に表示されます。 % curl http://www.example.tld/file/test.txt > test.txt % curl -o test.txt http://www.example.tld/file/test.txt % curl -O http://www.example.tld/file/test.txt 上記のコマンドはいずれもURLで示されたファイルの中身をカレントディレクトリのtest.txtに出力します。 また、HTTPのリダイレクトが発生した場合には、それに追従する動作を行いません。 % curl -L http://www.example.tld/file/test.txt デフォルトでは、curlコマンドはデータの取得情報をプログレスメータとしてリアルタイムに表示しますが、 % curl -o /dev/null http://www.example.tld/file/test.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 5086 221 5086 11242 0 0 47344 0 --:--:-- --:--:-- --:--:-- 47344 % % curl -s -o /dev/null http://www.example.tld/file/test.txt -o /dev/null % curlコマンドの性能計測機能 †curlコマンドにはファイルを取得するだけでなく、 以下のような情報を取得することができます。
time_*やspeed_*などの情報は性能計測に有用でしょう。 性能情報のフォーマットファイル †まず、curl_perf_format.txtという名前のファイルをカレントディレクトリに作成し、 以下のようなファイルを作成しました。 url_effective: %{url_effective}\n http_code: %{http_code}\n time_total(sec): %{time_total}\n time_namelookup(sec): %{time_namelookup}\n time_connect(sec): %{time_connect}\n time_appconnect(sec): %{time_appconnect}\n time_pretransfer(sec): %{time_pretransfer}\n time_redirect(sec): %{time_redirect}\n time_starttransfer(sec): %{time_starttransfer}\n size_download(byte): %{size_download}\n size_upload(byte): %{size_upload}\n size_header(byte): %{size_header}\n size_request(byte): %{size_request}\n speed_download(byte/sec): %{speed_download}\n speed_upload(byte/sec): %{speed_upload}\n content_type: %{content_type}\n num_connects: %{num_connects}\n num_redirects: %{num_redirects}\n redirect_url: %{redirect_url}\n curlコマンドで性能計測を行う †以下のようなオプションを付けてcurlを実行します。 % curl -s -w @perf_format.txt -o /dev/null http://www.example.tld/file/test.txt url_effective: http://www.example.tld/file/test.txt http_code: 200 time_total(sec): 0.231 time_namelookup(sec): 0.042 time_connect(sec): 0.056 time_appconnect(sec): 0.000 time_pretransfer(sec): 0.056 time_redirect(sec): 0 time_starttransfer(sec): 0.112 size_download(byte): 11162 size_upload(byte): 0 size_header(byte): 1534 size_request(byte): 352 speed_download(byte/sec): 48265.000 speed_upload(byte/sec): 0.000 content_type: text/html; charset=Shift_JIS num_connects: 2 num_redirects: 0 redirect_url: % コマンド実行後、端末画面にcurl_perf_format.txtで指定したフォーマットで、このファイル取得実行時の性能情報が表示されています。 以上、curlコマンドを使って、ネットワーク性能の計測を行う方法についてでした。 |