Apache-bench-comparison-of-outputs
Apacheベンチ-出力の比較
この章では、フラグありとフラグなしの出力を比較します。 適切なフラグを使用すると、Webアプリケーションのパフォーマンスがどのように向上するかを見てみましょう。 その前に、アプリケーションが単純な場合に違いに気付かない場合があることを理解する必要があります。 フラグを使用する場合とフラグを使用しない場合の単純なアプリケーションの場合と同様です。 次に、https://www.apache.org/URLを使用して同じテストを実行し、違いを確認します。
フラグなしでアプリケーションをテストする
このセクションでは、フラグなしでアプリケーションをテストする方法を理解します。
$ ab -n 100 -c 10 http://127.0.0.1:8000/
出力
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software: Rocket
Server Hostname: 127.0.0.1
Server Port: 8000
Document Path: /
Document Length: Variable
Concurrency Level: 10
Time taken for tests: 0.244 seconds
Complete requests: 100
Failed requests: 0
Non-2xx responses: 100
Keep-Alive requests: 0
Total transferred: 27700 bytes
HTML transferred: 6600 bytes
Requests per second: 2208.77 [#/sec] (mean)
Time per request: 4.527 [ms] (mean)
Time per request: 0.453 [ms] (mean, across all concurrent requests)
Transfer rate: 597.49 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 2 0.7 2 3
Processing: 0 2 0.7 2 4
Waiting: 0 2 1.0 2 3
Total: 4 4 0.3 4 5
Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 5
80% 5
90% 5
95% 5
98% 5
99% 5
100% 5 (longest request)
フラグを使用したアプリケーションのテスト
このセクションでは、フラグを使用してアプリケーションをテストする方法を理解します。
$ ab -l -r -n 100 -c 10 -k -H "Accept-Encoding: gzip, deflate" http://127.0.0.1:8000/
出力
...
Requests per second: 2277.07 [#/sec] (mean)
Time per request: 4.392 [ms] (mean)
Time per request: 0.439 [ms] (mean, across all concurrent requests)
Transfer rate: 615.97 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 2 0.7 2 3
Processing: 0 2 0.7 2 4
Waiting: 0 2 1.0 2 3
Total: 4 4 0.2 4 5
Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 4
80% 4
90% 5
95% 5
98% 5
99% 5
100% 5 (longest request)
出力統計に大きな違いはないことに注意してください。
フラグなしのApache組織Webサイトのテスト
フラグなしでApache Organization Webサイトをテストする方法を見てみましょう。
$ ab -n 100 -c 10 http://www.apache.org/
出力
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.apache.org (be patient).....done
Server Software: Apache/2.4.7
Server Hostname: www.apache.org
Server Port: 80
Document Path: /
Document Length: 58433 bytes
Concurrency Level: 10
Time taken for tests: 1.498 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 5877500 bytes
HTML transferred: 5843300 bytes
Requests per second: 66.74 [#/sec] (mean)
Time per request: 149.840 [ms] (mean)
Time per request: 14.984 [ms] (mean, across all concurrent requests)
Transfer rate: 3830.58 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 12 110 295.2 12 1012
Processing: 37 38 0.5 38 39
Waiting: 12 13 0.3 13 15
Total: 49 147 295.4 50 1051
Percentage of the requests served within a certain time (ms)
50% 50
66% 50
75% 50
80% 50
90% 816
95% 1050
98% 1051
99% 1051
100% 1051 (longest request)
フラグを使用したApache組織Webサイトのテスト
次に、フラグを使用してApache Organization Webサイトをテストします。
$ ab -l -r -n 100 -c 10 -k -H "Accept-Encoding: gzip, deflate" http://www.apache.org/
出力
...
Document Length: Variable
Concurrency Level: 10
Time taken for tests: 0.357 seconds
Complete requests: 100
Failed requests: 0
Keep-Alive requests: 100
Total transferred: 1358510 bytes
HTML transferred: 1317700 bytes
Requests per second: 280.28 [#/sec] (mean)
Time per request: 35.678 [ms] (mean)
Time per request: 3.568 [ms] (mean, across all concurrent requests)
Transfer rate: 3718.41 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.7 0 12
Processing: 14 17 21.3 15 227
Waiting: 14 17 21.3 14 227
Total: 14 18 21.5 15 227
Percentage of the requests served within a certain time (ms)
50% 15
66% 15
75% 15
80% 15
90% 27
95% 28
98% 29
99% 227
100% 227 (longest request)
フラグを使用すると、1秒あたりのリクエストがどのように増加したかを簡単に確認できます。 この場合、特に -H "Accept-Encoding:gzip 、deflateの使用が原因です。このフラグはApacheサーバーにリクエストを gzipped 形式で処理するよう指示するためです。
Apacheベンチの結果を考慮する
Apache Benchの結果に関しては、いくつかの重要な点を考慮する必要があります。 これは、アプリケーションのボトルネックを取り除き、パフォーマンスを改善するための全体的な戦略を設計するのに役立ちます。
1秒あたりのリクエスト数が必要です。 これにより、Webサーバーのセットアップがどの程度うまく機能しているかがわかります。数値が大きいほど、パフォーマンスが向上します。 次に、接続時間(ミリ秒)と処理された要求の割合が表示されます。 これらのメトリックを目的のパフォーマンスに変更するには、Webサーバーの設定を微調整する必要がある場合があります。
Apacheまたは使用されているウェブサーバーのエラーログまたは(一般的な)ログにエラーがないか確認します。 負荷を増やすと、物事が窒息し始めます。メモリの問題が発生し始めます。 多くのpythonスクリプトは、並行性を念頭に置いて書かれていないとクラッシュし始めます。
Webサーバーがクラッシュしたりタイムアウトしたりする、それを超える重大な同時実行性の値を調べる必要がありますか? 通常、これはかなり高い並行性レベルで発生するはずです。 この値が低い場合、何かが間違っているため、これらの設定を低く/高く調整する必要があります。
結論
このチュートリアルでは、Apache Benchを使用してWebサイトまたはWebアプリケーションをロードテストする方法を学びました。 Apache Benchは、ボトルネックを減らし、パフォーマンスを向上させるために、Webアプリケーションサーバーのセットアップをどのように改善すべきかを判断するための非常に貴重なツールです。 Apache Benchの基本的な使用法を理解したので、さまざまなシナリオでアプリケーションのパフォーマンスを測定するための新しいテスト計画を作成することから始めます。