Hatena::ブログ(Diary)

FAT47の底辺インフラ議事録

2011-09-28 Apache Benchの利用

Apache Benchの利用

apache benchはApacheに付属している負荷試験用のソフトウェアです。

簡易なテストであれば十分に利用できます。

注意点としては、単一のリクエストに対してのテストしか実行してくれません。

というのは、アクセス先のプログラムが画像データを利用していたとしても、画像のリクエスト処理は行われません。

総合的な負荷試験を行いたい場合はJMeterを利用しましょう。

JMeterによる負荷試験 その1 導入から実行まで


abコマンドの利用方法

※自分が管理しているサーバ以外で絶対に実行しないでください。ユーザエージェントにApache Benchとしてアクセスログに記録されるのでバレます。

ab -n リクエスト数 -c 同時実行のリクエスト数 サーバーアドレス

というように利用します。

ab -n 10000-c 100 http://localhost

この例だと同時100接続で10000リクエストを処理させることになります。

他にもabには様々なオプションが存在します。

ab -h

Usage: ab [options] [http[s]://]hostname[:port]/path

Options are:

-n requests Number of requests to perform

-c concurrency Number of multiple requests to make

-t timelimit Seconds to max. wait for responses

-p postfile File containing data to POST

-T content-type Content-type header for POSTing

-v verbosity How much troubleshooting info to print

-w Print out results in HTML tables

-i Use HEAD instead of GET

-x attributes String to insert as table attributes

-y attributes String to insert as tr attributes

-z attributes String to insert as td or th attributes

-C attribute Add cookie, eg. 'Apache=1234. (repeatable)

-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'

Inserted after all normal header lines. (repeatable)

-A attribute Add Basic WWW Authentication, the attributes

are a colon separated username and password.

-P attribute Add Basic Proxy Authentication, the attributes

are a colon separated username and password.

-X proxy:port Proxyserver and port number to use

-V Print version number and exit

-k Use HTTP KeepAlive feature

-d Do not show percentiles served table.

-S Do not show confidence estimators and warnings.

-g filename Output collected data to gnuplot format file.

-e filename Output CSV file with percentages served

-h Display usage information (this message)

-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)

-f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

主なオプションは以下にまとめました。

-n発行するリクエストの回数
-c同時に発行するリクエストの数
-tレスポンスの待ち時間の秒数
-pサーバへ送信するファイルを指定
-TContent-typeヘッダーを指定
-w結果をHTMLで出力
-CCookieを指定
-ABasic認証を利用する
-Xプロキシ経由でリクエスト
-Vabのバージョン表示
-kKeepAliveの有効化