LoginSignup
0
0

More than 1 year has passed since last update.

Amazon Linux2 に負荷ツールtsungをインストールして負荷をかける

Last updated at Posted at 2023-04-05

Amazon Web Services負荷試験入門 ――クラウドの性能の引き出し方がわかる Software Design plus

以前、月間そこそこアクセスのあるWebアプリケーションをAWSに移行した際、必要に迫られて買った。基本的にJmeterなどの利用方法が書かれていたりして、これも現場で活用できる本だった。
その中で、tsungというあまり聞かない負荷ツールが紹介されていた。

仕事で「代紋take2」みたいな出来事があって、必要に迫られて負荷を試さなきゃならない事案があり、tsungを試すことになった。

「代紋take2」みたいな出来事↓
45A42267-283C-4640-B569-E2483AF7FEF5.png

インストール方法なども基本英語で、日本で試している人も希少だったのでややてこずった。が、使い勝手としては非常に良い負荷ツールだった。Jmeterより細かく負荷を設定できる。備忘としてメモ。

前提

  • Amazon Linux 2にインストール

やり方

管理者昇格。

$ sudo su -

Gitインストール

# yum -y install git

tsungダウンロード

# mkdir -p work
# ll
# cd ~/work
# ll
# pwd
# git clone https://github.com/processone/tsung
# ll

必要パッケージインストール

./configureでエラーが出たので、インストールする。

# yum -y install epel-release
# yum -y install epel
# yum -y install gnuplot gnuplot-common
# yum -y install perl-Template-Toolkit
# yum -y update glib2
# yum install gcc -y
# yum install ncurses ncurses-devel openssl openssl-devel gcc-c++ unixODBC unixODBC-devel fop *openjdk-devel inotify-tools
# yum --enablerepo=epel install inotify-tools
# yum install autoconf -y

Erlang OTPのインストール

# cd ../
# wget http://erlang.org/download/otp_src_19.3.tar.gz
# ls -lh
# tar zxvf otp_src_19.3.tar.gz
# ll
# cd otp_src_19.3
# ll
# ./configure
# make
# make install
# erl -version

tsungインストール

# cd ../
# ll
# cd tsung/
# ./configure
# make
# make install
# yum install -y gnuplot
# tsung -v
# ll

ulimit,カーネルパラメータ変更

limits.confに追記する。

# ulimit -n
# vi /etc/security/limits.conf
~~以下はvi編集操作~~
*  soft  nofile  1024000
*  hard  nofile  1024000

いったんログアウト

# exit
# exit

再度入りなおす

$ sudo su -
# ulimit -n

sysctl.confに追記する。

# vi /etc/sysctl.conf
~~以下はvi編集操作~~
# General gigabit tuning
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216

# This gives the kernel more memory for TCP
# which you need with many (100k+) open socket connections
net.ipv4.tcp_mem = 50576 64768 98152

# Backlog
net.core.netdev_max_backlog = 2048
net.core.somaxconn = 1024
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_syncookies = 1

反映。

# sysctl -p

シナリオファイル作成

# cd work/
# mkdir logs
# ll
# cd logs/
# cd ../
# touch stress-test.xml
# ll

空ファイルを開いて、シナリオをXML形式で編集して保存する。

# vi stress-test.xml

server host="TESTWEBSITE.co.jp"の部分を、負荷をかけたいアドレスに変える。

stress-test.xml
<!DOCTYPE tsung SYSTEM "/usr/local/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
  <clients>
    <client host="localhost" weight="1" cpu="1" maxusers="5000"/>
  </clients>
<servers>
  <server host="TESTWEBSITE.co.jp" port="443" type="ssl"></server>
</servers>

  <load>
   <arrivalphase phase="1" duration="2" unit="minute">
     <users maxnumber="3000" arrivalrate="100" 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="stress-test" probability="100" type="ts_http">

    <for from="1" to="10" var="i">
      <request subst="true">
        <http url="/" method="GET" version="1.1">
        </http>
      </request>
    </for>

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

細かい書き方は当時は英語サイトしかなかったのでつらかったが、今であればChatGPTに頼めば・・・(笑)
数値なども増やすことで、負荷の量を増やすことが可能。

シナリオ実行

# tsung -l logs -f stress-test.xml start

実行すると、指定したアドレスにアクセスして負荷をかける。実行結果のログも吐き出されるため、必要に応じて確認する。

参考

★とても参考になった→2017年版 負荷テストツールTsungをAWS EC2 AmazonLinuxでクラスタリング構築
https://msitter29.hatenablog.com/entry/2017/05/07/194559

★とても参考になった→tsungでサクッと負荷テストをしよう
https://tech.techtouch.jp/entry/how-to-tsung

Tsungによるwebsocket負荷テスト(日本語説明付き
https://gist.github.com/georgeOsdDev/9988060

負荷テストはtsungを使ってみよう(使い方まとめ)
https://tachitechi.com/%E8%B2%A0%E8%8D%B7%E3%83%86%E3%82%B9%E3%83%88%E3%81%AF%E3%80%81tsung%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86%EF%BC%88%E4%BD%BF%E3%81%84%E6%96%B9%E3%81%BE%E3%81%A8%E3%82%81/

tsung でサーバを高負荷テスト
https://qiita.com/Kakimoty_Field/items/44c0cfe5051bf2a46d3d

Tsungで負荷テストしよう(1) - 基礎知識
https://heartbeats.jp/hbblog/2016/10/tsung.html

Elixir初心者がOTPって結局なんなのか調べてみた
https://qiita.com/kaonash/items/d3678d5635e9d1e57ccf

余談

ChatGPTを使ってみた記事を書いたが、いざ触ってみるとなかなか衝撃的ですごい。これはもはやIT領域で人間がだいぶ減るかも?と思った。具体的な指示とかは必要だけど、コーディングとかは自動でやってくれる。とはいえ、けっこう嘘もあるので、そこを見抜く力は必要。
難しかったことをこれだけいろいろやって、正解率もそこそこ高いのはすごい。

マイクロソフトがOpenAIに出資してる都合上、一歩リードしているそうだけど、なかなかIT業界も波乱になりそうな感じだ。今もアメリカはインフレや、レイオフが起きているが、AIの発達によりさらに大きい荒波が来そうな気配はある。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0