Apache Benchでパフォーマンス測定する
サイト作成していて、負荷テストにはまっていました。
便利なパフォーマンス測定ができるものがありますね。
パフォーマンス測定
Apache Bench
こちらを使用すれば、サイトに負荷をかけてレスポンスの向上するのかが確かめることができます。
ab -n 100 -c 100 http://www.example.co.jp/
-n
はTotalで送るリクエストになります。
-c
は同時に送る数になります。
この場合は、100のリクエストを同時に100個投げるようになります。
実験結果を出すために、今回は50にしてみます。
本当はexample.comには送信していなくて、実験中のサイトになります。
ab -n 50 -c 50 http://www.example.co.jp/
実験結果は次のようになります。
Server Software: nginx/1.6.2 Server Hostname: example.com Server Port: 80 Document Path: / Document Length: 33834 bytes Concurrency Level: 50 Time taken for tests: 2.817 seconds Complete requests: 50 Failed requests: 0 Total transferred: 1728450 bytes HTML transferred: 1691700 bytes Requests per second: 17.75 [#/sec] (mean) Time per request: 2817.040 [ms] (mean) Time per request: 56.341 [ms] (mean, across all concurrent requests) Transfer rate: 599.19 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 51 61 4.0 63 64 Processing: 152 1236 680.3 1222 2753 Waiting: 126 1186 647.9 1192 2416 Total: 203 1297 683.1 1284 2816 Percentage of the requests served within a certain time (ms) 50% 1284 66% 1743 75% 1809 80% 2019 90% 2261 95% 2354 98% 2816 99% 2816 100% 2816 (longest request)
リクエストがどのくらい成功しているかの判定
Complete requests: 50 Failed requests: 0
こちらになります。 今回の場合は、全部捌けていますね。
秒間捌けるリクエスト数
Requests per second: 17.75 [#/sec] (mean)
17アクセス捌いていたことになります。
リクエストの処理時間
Time per request: 56.341 [ms] (mean, across all concurrent requests)
こちらになります。
56msになります。
ベンチマーク取ることで、速度向上しているかがわかるようになります。
参考: