轉: Tsung:開源多協議分布式負載&壓力測試工具
Main features
- High Performance: the load can be distributed on a cluster of client machines
- Multi-protocols using a plugin system: HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP , XMPP/Jabber, BOSH, MQTT and AMQP are currently supported. SSL is also supported.
- Several IP addresses can be used on a single machine using the underlying OS IP Aliasing
- OS monitoring (CPU, memory and network traffic) using SNMP, Munin or Erlang agents on remote servers.
- XML configuration system; several sessions can be used to simulate different type of users. Dynamic sessions can be easily described in XML (this can be used to retrieve at runtime an ID from the server output and use it later in the session).
- In order to generate a realistic traffic, user think-times and the arrival rate can be randomize using a probability distribution
- HTML reports can be generated during the load to view response times measurement, server CPU, etc.
Tsung is developed in Erlang,運行Tsung,需要相關erlang依賴包支持。
簡介
Tsung 是一個壓力測試工具,可以測試包括HTTP, WebDAV, PostgreSQL, MySQL, LDAP, and XMPP/Jabber等服務器。針對 HTTP 測試,Tsung 支持
HTTP 1.0/1.1 ,包含一個代理模式的會話記錄、支持 GET、POST 和 PUT 以及 DELETE 方法,支持 Cookie 和基本的WWW 認證,同時還支持 SSL。
tsung的工作原理
(1) Tsung的每一個虛擬用戶就是一個erlang的輕量進程。這點和loadrunner有很大的區別。
(2) 虛擬用戶完成session後就消失。
(3) 大量的虛擬用戶(erlang輕量進程)建立在erlangVM上。
(4) 一臺測試機可以啟多個erlangVM,目前按照1個cpu啟動1個erlangVM。
一、安裝前檢查環境
1、查看環境:
[root@localhost bin]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.4 (Final) Release: 6.4 Codename: Final
2、確保安裝了以下工具:
yum install gcc -y yum install perl -y yum install unixODBC yum install unixODBC-devel
二、安裝
1、下載並安裝erlang
[root@localhost ~]#cd /usr/local [root@localhost local]#mdir -p erlang [root@localhost local]# wget http://www.erlang.org/download/otp_src_R14B04.tar.gz [root@localhost local]# tar -zxvf otp_src_R14B04.tar.gz [root@localhost local]# cd otp_src_R14B04 [root@localhost otp_src_R14B04]# ./configure --prefix=/usr/local/erlang [root@localhost otp_src_R14B04]# make [root@localhost otp_src_R14B04]# make install
註意:如果出現 "configure: error: No curses library functions found "錯誤,嘗試安裝:
[root@localhost otp_src_R14B04]#yum install -y ncurses-devel
2、下載並安裝Tsung
[root@localhost ~]#cd /usr/local [root@localhost local]#mkdir -p tsung
[root@localhost local]# wget http://tsung.erlang-projects.org/dist/tsung-1.4.2.tar.gz [root@localhost local]# tar -zxvf tsung-1.4.2.tar.gz [root@localhost local]# cd tsung-1.4.2 [root@localhost tsung-1.4.2]# ./configure --prefix=/usr/local/tsung --with-erlang=/usr/local/erlang [root@localhost tsung-1.4.2]# make [root@localhost tsung-1.4.2]# make install
3、下載並安裝perl Template,用於生成報告模版
[root@localhost ~]#cd /usr/local [root@localhost local]# wget http://cpan.org/modules/by-module/Template/Template-Toolkit-2.24.tar.gz [root@localhost local]# tar -zxvf Template-Toolkit-2.24.tar.gz [root@localhost local]# cd Template-Toolkit-2.24 [root@localhost Template-Toolkit-2.24]# perl Makefile.PL [root@localhost Template-Toolkit-2.24]# make [root@localhost Template-Toolkit-2.24]# make test [root@localhost Template-Toolkit-2.24]# make install
註意:如果出現 以下提示:
[root@localhost Template-Toolkit-2.24]# perl Makefile.PL Can‘t locate ExtUtils/MakeMaker.pm in @INC (@INC contains: ./lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 11. BEGIN failed--compilation aborted at Makefile.PL line 11.
解決辦法:
yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
4、下載並安裝gnuplot,用於聊天生成
[root@localhost local]#yum install -y gnuplot gd libpng zlib
三、檢查是否安裝成功
[root@localhost local]# perl -v 命令查看顯示perl 當前版本信息。 [root@localhostlocal]# gnuplot 命令查看gnuplot 的安裝版本 [root@localhost local]# erl 命令查看erlang的安裝版本 Erlang R14B04 (erts-5.8.5) [source] [64-bit] [rq:1] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) [root@localhost local]# tsung -v 命令查看tsung 的安裝版本
Tsung version 1.4.2
四、安裝後設置環境變量
安裝成後添加erlang、tsung環境變量
[root@localhost local]# vim /etc/profile export PATH=$PATH:$JAVA_HOME/bin:/usr/local/erlang/bin:/usr/local/tsung/bin:/usr/local/nginx/sbin:$PATH(修改自己實際變量) :wq保存,退出 [root@localhost local]# source /etc/profile 不報錯則成功 [root@localhost local]# tsung -v Tsung version 1.4.2 [root@localhost local]# erl -v Erlang R14B04 (erts-5.8.5) [source] [64-bit] [rq:1] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) 1>
五、使用並生成報表
1、在root文件夾下新建.tsung目錄,用於存放log和xml配置,測試配置文件可參考/usr/local/tsung/share/doc/tsung/examples/目錄下配置
[root@localhost local]#mkdir ~/.tsung [root@localhost local]#cp /usr/local/tsung/share/doc/tsung/examples/http_simple.xml ~/.tsung/tsung.xml
2、運行,默認執行腳本~/.tsung/tsung.xml配置
[root@localhost local]# tsung start Starting Tsung "Log directory is: /root/.tsung/log/20150311-0536"
3、進入Log目錄下可以看到生成的報表信息
[root@localhost 20150311-0536]# cd /root/.tsung/log/20150311-0536 [root@localhost 20150311-0536]# ls -a . .. match.log [email protected] tsung.log tsung.xml
4、進入需要生成圖形報表的Log目錄,如/root/.tsung/log/20150311-0536
[root@localhost 20150311-0536]# /usr/local/tsung/lib/tsung/bin/tsung_stats.pl creating subdirectory data creating subdirectory gnuplot_scripts creating subdirectory images No data for Session No data for Perfs No data for Transactions No data for Match No data for Event No data for Async No data for Size size_rcv is equal to 0 ! size_sent is equal to 0 ! [root@localhost 20150311-0536]# ls data gnuplot.log gnuplot_scripts graph.html images match.log report.html [email protected] tsung.log tsung.xml
5、將report.html拖到windows系統中,直接打開即可查看。
目前Tsung工具的最新版本為1.6.0,需要註意的是Tsung1.5.1版本及以上才支持MQTT,並且只有Tsung1.6.0開始,才支持MQTT的username和password的認證。
Tsung測試工具的基本測試命令為 Tsung -f ~/.tsung/mqtt.xml -l <日誌保存路徑> start
mqtt.xml具體如下(在/usr/share/doc/tsung/examples路徑下可查找到):
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="debug" version="1.0">
<!--下面為客戶端配置,可以有配有多個客戶端,其中ubuntu要保證通過ssh ubuntu能遠程登陸上ubuntu這臺機器,這裏建議通過密鑰對來進行遠程客戶端的登陸。下面類似於loadrunner的load generator,用以模擬用戶。具體的詳細配置請參見官網文檔http://tsung.erlang-projects.org/user_manual/conf-client-server.html-->
轉: Tsung:開源多協議分布式負載&壓力測試工具