Apache
Apacheに付属するApacheBenchというプログラムで単一のURLに対して負荷テストを行うことができます。
※複数のURLに対して複雑なテストを行いたい場合は、Apache JMeter等がつかえます。
「-n」でリクエスト数を、「-c」で同時接続数を指定します。
$ ab -n 100 -c 100 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking example.com (be patient).....done
Server Software: Apache
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 13888 bytes
Concurrency Level: 100
Time taken for tests: 6.815 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1432400 bytes
HTML transferred: 1388800 bytes
Requests per second: 14.67 (mean)
Time per request: 6815.211 [ms] (mean)
Time per request: 68.152 [ms] (mean, across all concurrent requests)
Transfer rate: 205.25 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 119 163 25.8 163 209
Processing: 97 3593 1900.9 3737 6696
Waiting: 78 3569 1903.5 3691 6678
Total: 217 3756 1914.7 3912 6815
Percentage of the requests served within a certain time (ms)
50% 3912
66% 4911
75% 5451
80% 5824
90% 6346
95% 6646
98% 6751
99% 6815
100% 6815 (longest request)
BASIC認証が必要な場合は「-A」で、ユーザー名:パスワードを指定します。
ab -n 100 -c 100 -A ユーザー名:パスワード "http://localhost/param1=value1¶m2=value2"
GET
- クエリーストリングを含むURLを「”」でくくります
ab -n 100 -c 100 -A ユーザー名:パスワード http://localhost/?
POST
- ポストするデータをテキストファイルに記述し、「-p」でそのファイル名を、「-T」でポストするデータのContent-typeを指定します。
ab -n 10 -c 10 -p post_data.txt -T "application/x-www-form-urlencoded" http://localhost/
ポストデータファイルは以下のように記述し、URLエンコードしたものを使います。
param1=value1¶m2=value2+value3
URLエンコードされたファイルを作成する例です。
php -r 'echo urlencode("param1=value1¶m2=value2+value3");' > post_data.txt
ab -n 100 -c 10 -p post_file -T "multipart/form-data"