# tsungを使ったパフォーマンステスト

- URL: https://tech.fusic.co.jp/posts/2018-12-04-tsung/
- 公開日: 2018-12-04
- 著者: shiro seike / せいけ しろう / 清家 史郎
- 掲載: Fusic Tech Blog（株式会社Fusic）

> 清家です。 最近は登壇駆動の影響でパフォーマンス測…[続きを読むtsungを使ったパフォーマンステスト](https://tech.fusic.co.jp/uncategorized/tsung%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e3%83%91%e3%83%95%e3%82%a9%e3%83%bc%e3%83%9e%e3%83%b3%e3%82%b9%e3%83%86%e3%82%b9%e3%83%88/)<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt -->

---

清家です。  
最近は登壇駆動の影響でパフォーマンス測定を行ってます。

普段はすらっと ApacheBench で終わりなんですが、  
それだと役不足になりつつあるので tsung と呼ばれる Erlang 製のツールを使ってます。

Mac 環境だと`brew install`でサクッと入ります。

```bash; title:
$ brew install tsung
```

準備が整ったので実際に負荷試験を行います。  
以下の様な XML を配置して実行します。

```xml; title:
\<?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' maxusers="100" use\_controller\_vm="true"/\>
 \</clients\>
 \<servers\>
 \<server host="192.168.33.46" port="80" type="tcp"/\>
 \</servers\>
 \<load\>
 \<arrivalphase phase="1" duration="120" unit="second"\>
 \<users maxnumber="50" arrivalrate="10000" unit="second"/\>
 \</arrivalphase\>
 \</load\>
 \<sessions\>
 \<session probability="100" name="http-test" type="ts\_http"\>
 \<for from="1" to="100" incr="1" var="counter"\>
 \<setdynvars sourcetype="random\_number" start="3" end="32"\>
 \<var name="rndint" /\>
 \</setdynvars\>
 \<request\>
 \<http url="/index.php" version="1.1" contents="rndint=%%\_rndint%%" method="POST"\>
 \</http\>
 \</request\>
 \</for\>
 \</session\>
 \</sessions\>
 \</tsung\>
```

log を logs ディレクトリに出力しながら実行

```bash; title:
$ tsung -f ./tsung.xml -l logs start
```

すると logs 配下にファイルが出来るので解析を行います。

`/usr/local/lib/tsung/bin/tsung_stats.pl`に解析用の perl モジュールがあるのですが、  
シェバンが`/usr/bin/perl`固定になっているので、自分の perl のパスを which で調べて変更します。

もしくは`/usr/bin/perl`が利用される用に PATH の調整をしても良いかもしれません。

```plain; title:
$ which perl
 /usr/local/bin/perl

 $ vim /usr/local/lib/tsung/bin/tsung\_stats.pl

 #!/usr/bin/perl -w
 ↓に変更
 #!/usr/local/bin/perl -w
```

解析実行

```bash; title:
$ cd logs/yyyymmdd-hhmi
 $ /usr/local/lib/tsung/bin/tsung\_stats.pl --stats tsung.log
```

すると HTML ファイルが出来上がるので結果が確認出来ます。

```bash; title:
open report.html
```

![](/uploads/tsung-800x354.png)

<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->
