負荷試験ツール tsung

Pocket

cuiでやりたかった

読み方不明 誰か教えて

環境はとりあえずmacで
brew でインストールできる

% brew install tsung

centosだとyumで入るので便利

Template-Toolkitをインストールする

% sudo cpan Template

全部空エンターで

作業ディレクトリを作成

% mkdir ~/tsung

結果を保存するlogsディレクトリも先に作っておく

% mkdir ~/tsung/logs

以下~/tsungディレクトリで作業

xmlを作成
exampleは自分の環境だとここにできてた

% ls -l /usr/local/Cellar/tsung/1.7.0/share/doc/tsung/examples/http_simple.xml

作業ディレクトリにコピる

% cp /usr/local/Cellar/tsung/1.7.0/share/doc/tsung/examples/http_simple.xml http_simple.xml

コメントアウト外したexample

% cat http_simple.xml
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/local/Cellar/tsung/1.7.0/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">

  <clients>
    <client host="localhost" use_controller_vm="true"/>
  </clients>

<servers>
  <server host="myserver" port="80" type="tcp"></server>
</servers>

  <monitoring>
    <monitor host="myserver" type="snmp"></monitor>
  </monitoring>

  <load>
   <arrivalphase phase="1" duration="10" unit="minute">
     <users interarrival="2" unit="second"></users>
   </arrivalphase>
  </load>

  <options>
   <option type="ts_http" name="user_agent">
    <user_agent probability="80">Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21</user_agent>
    <user_agent probability="20">Mozilla/5.0 (Windows; U; Windows NT 5.2; fr-FR; rv:1.7.8) Gecko/20050511 Firefox/1.0.4</user_agent>
   </option>
  </options>


 <sessions>
  <session name="http-example" probability="100" type="ts_http">


    <request> <http url="/" method="GET" version="1.1"></http> </request>
    <request> <http url="/images/accueil1.gif" method="GET" version="1.1" if_modified_since="Fri, 14 Nov 2003 02:43:31 GMT"></http> </request>
    <request> <http url="/images/accueil2.gif" method="GET" version="1.1" if_modified_since="Fri, 14 Nov 2003 02:43:31 GMT"></http> </request>
    <request> <http url="/images/accueil3.gif" method="GET" version="1.1" if_modified_since="Fri, 14 Nov 2003 02:43:31 GMT"></http> </request>

    <thinktime value="20" random="true"></thinktime>

    <request> <http url="/index.en.html" method="GET" version="1.1" ></http> </request>

  </session>
 </sessions>
</tsung>

詳しくは公式のドキュメントに書いてる
http://tsung.erlang-projects.org/user_manual/configuration.html

そのままどっかにあるのコピって

<!DOCTYPE tsung SYSTEM "/usr/local/Cellar/tsung/1.7.0/share/tsung/tsung-1.0.dtd">

がミスってて動かねーとかあったのでそんなことないように

上から説明しながら自分の設定ように書き換える

接続先の設定 cliantはlocalhostから投げるのでそのまま
投げ先は自分のサイトへ

  <server host="myserver" port="80" type="tcp"></server>

  <server host="astail.net" port="443" type="ssl"></server>

<monitoring> は今回いらなそうなので消す

どの程度負荷をかけるか
デフォルトのこれだと10分間 2秒ごとに新規にアクセスするかな

   <arrivalphase phase="1" duration="10" unit="minute">
     <users interarrival="2" unit="second"></users>
   </arrivalphase>


1分間 0.1秒ごとにアクセス
単純計算 1秒10リクエスト  * 60 = 600

   <arrivalphase phase="1" duration="1" unit="minute">
     <users interarrival="0.1" unit="second"></users>
   </arrivalphase>

アクセス情報 割合

   <option type="ts_http" name="user_agent">
    <user_agent probability="80">Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21</user_agent>
    <user_agent probability="20">Mozilla/5.0 (Windows; U; Windows NT 5.2; fr-FR; rv:1.7.8) Gecko/20050511 Firefox/1.0.4</user_agent>
   </option>


1つでいいです 面倒だし

   <option type="ts_http" name="user_agent">
    <user_agent probability="100">Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21</user_agent>
   </option>

どこにアクセスするか

  <session name="http-example" probability="100" type="ts_http">
    <request> <http url="/" method="GET" version="1.1"></http> </request>
    <request> <http url="/images/accueil1.gif" method="GET" version="1.1" if_modified_since="Fri, 14 Nov 2003 02:43:31 GMT"></http> </request>
    <request> <http url="/images/accueil2.gif" method="GET" version="1.1" if_modified_since="Fri, 14 Nov 2003 02:43:31 GMT"></http> </request>
    <request> <http url="/images/accueil3.gif" method="GET" version="1.1" if_modified_since="Fri, 14 Nov 2003 02:43:31 GMT"></http> </request>

    <thinktime value="20" random="true"></thinktime>
    <request> <http url="/index.en.html" method="GET" version="1.1" ></http> </request>

  </session>


astail.net/?p=1461 へ負荷をかける

  <session name="http-example" probability="100" type="ts_http">
    <request> <http url="/?p=1461" method="GET" version="1.1"></http> </request>
  </session>

こうなった

% cat http_simple.xml
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/local/Cellar/tsung/1.7.0/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">

  <clients>
    <client host="localhost" use_controller_vm="true"/>
  </clients>

<servers>
  <server host="astail.net" port="443" type="ssl"></server>
</servers>

  <monitoring>
    <monitor host="myserver" type="snmp"></monitor>
  </monitoring>

  <load>
   <arrivalphase phase="1" duration="1" unit="minute">
     <users interarrival="0.1" unit="second"></users>
   </arrivalphase>
  </load>

  <options>
   <option type="ts_http" name="user_agent">
    <user_agent probability="80">Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21</user_agent>
    <user_agent probability="20">Mozilla/5.0 (Windows; U; Windows NT 5.2; fr-FR; rv:1.7.8) Gecko/20050511 Firefox/1.0.4</user_agent>
   </option>
  </options>

 <sessions>
  <session name="http-example" probability="100" type="ts_http">
    <request> <http url="/?p=1461" method="GET" version="1.1"></http> </request>
  </session>
 </sessions>
</tsung>

実行

% tsung -l logs -f http_simple.xml start
Starting Tsung
Log directory is: /Users/astel/tsung/logs/20171130-1802
[os_mon] cpu supervisor port (cpu_sup): Erlang has closed

結果は /Users/astel/tsung/logs/20171130-1802 に出ている
これをレポートとしてhtmlファイルに出す

centosとかならコマンド化されてるけどmacはplを叩く
/usr/local/lib/tsung/bin/tsung_stats.pl があることを確認しておく

ワンライナー化
最新のログディレクトリに移動してtsung_stats.plを叩いてreport.htmlを作成、それを開いてディレクトリを元の場所にもどる

% cd ./logs/`ls -t ./logs | head -n 1` ; /usr/local/lib/tsung/bin/tsung_stats.pl ; open report.html ; cd ../../

いろいろ見れる
graphとかもみれる

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください