Tsung
基礎
- 負荷テストツール
- サンプル
準備
サーバ側
- dstat -tlamp を実行する
- kernel: possible SYN flooding on port 80. Sending cookies
- sysctl -w net.ipv4.tcp_syncookies=0
クライアント側
カーネルチューニング
- net.ipv4.tcp_tw_reuse = 1
- net.ipv4.tcp_tw_recycle = 1
- net.ipv4.tcp_fin_timeout = 3
- net.ipv4.tcp_orphan_retries = 2
- net.core.somaxconn = 2048
- net.ipv4.ip_local_port_range = 1025 65000
- fs.file-max = 65000
- net.ipv6.conf.all.disable_ipv6 = 1
- net.ipv6.conf.default.disable_ipv6 = 1
- /etc/security/limits.conf
- soft nofile 65000
- hard nofile 65000-
maxnumber に達すると処理は終わる
- duration に指定した時間より短い場合でも
複数台構成の場合には master <=> slave で SSH 接続できる必要がある
コマンド
実行
# tsung -l logs -f tsung.xml start
グラフ生成
# tsung_stats --stats logs/20170613-0300/tsung.log
XML config
multi servers
<servers> <server host="192.168.12.10" port="80" type="tcp"></server> <server host="192.168.12.11" port="80" type="tcp"></server> <server host="192.168.12.12" port="80" type="tcp"></server> </servers>
request
<request> <http url="_static/basic.css" <http_header name="Host" value="example.com"/> <www_authenticate userid="test" passwd="test01" type="basic"/> </http> </request> <request> <http url="_static/jquery.js" <http_header name="Host" value="example.com"/> <www_authenticate userid="test" passwd="test01" type="basic"/> </http> </request>
フェーズの設定
<load> <arrivalphase phase="1" duration="1" unit="minute"> <users arrivalrate="5" maxnumber="50" unit="second"></users> </arrivalphase> <arrivalphase phase="1" duration="10" unit="minute"> <users arrivalrate="10" maxnumber="10000" unit="second"></users> </arrivalphase> </load>
- フェーズ 1
- 実行時間は 1 分間
- 1 秒ごとに 5 ユーザずつ増やし、最大 50 ユーザまで増やす
- フェーズ 2
- 実行時間は 10 分間
- 1 秒ごとに 10 ユーザずつ増やし、最大 10000 ユーザまで増やす
- フェーズ 1
ユーザエージェントの設定
<options> <option type="ts_http" name="user_agent"> <user_agent probability="50">Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36</user_agent> <user_agent probability="50">Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0</user_agent> </option> </options>
セッション設定
<sessions> <session name="http" probability="50" type="ts_http"> <request> <http url="/" method="GET" version="1.1"></http> </request> <request> <http url="/corporate/access.html" method="GET" version="1.1"></http> </request> <thinktime min="1" max="5" random="true"></thinktime> <request> <http url="/world/" method="GET" version="1.1"></http> </request> </session> <session name="http" probability="50" type="ts_http"> <request> <http url="/osp_blog/" method="GET" version="1.1"></http> </request> </session> </sessions>
- thinktime の設定で 1 〜 5 秒でランダムで止まる
ログイン施行後、ユーザページを表示(CSRF トークンを設定)
<session name="login" weight="1" type="ts_http"> <request> <dyn_variable name="authenticity_token"/> <http url="/login" method="GET"> <http_header name="Host" value="example.com"/> </http> </request> <setdynvars sourcetype="eval" code="fun({Pid,DynVars})-> {ok, Val} = ts_dynvars:lookup(authenticity_token, DynVars), list_to_binary(http_uri:encode(binary_to_list(Val))) end."> <var name="escaped_authenticity_token" /> </setdynvars> <request subst="true"> <http url="/login" version="1.1" method="POST" content_type="application/x-www-form-urlencoded" contents="utf8=%E2%9C%93&authenticity_token=%%_escaped_authenticity_token%%&login_form_params[mail]=test@example.com&login_form_params[pass]=xxxxxxx&" > <http_header name="Host" value="example.com"/> </http> </request> <request> <http url="/user/" method="GET" version="1.1"> <http_header name="Host" value="example.com"/> </http> </request> </session>
Error
Can't start newbeam on host
- ssh config の見直し
- selinux 無効化
- 双方向の ssh 接続が必要
dtd_not_found
- サンプルのファイルを変更してが得る必要がある
fatal, failed_validation, element_unauthorize_in_choice
- load の user が必要っぽい