关于学习TSUNG压力测试

分类:测试 |

上图3天内由0基础搞定 Tsung,  所查资料, 没舍得关掉的标签:  

image.png


总结: 以下是自己的使用记录, 有些是自己写的, 有些是来自网络: 感谢互联网: 

yum install glibc gcc perl unixODBC unixODBC-devel ncurses-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker gnuplot gd libpng zlib -y


成果:

image.png

安装所需软件已打包好,请下载: 

链接: http://pan.baidu.com/s/1dENv65z 密码: mmra


1.录制脚本

tsung-recorder -L 8888 start


浏览器配置代码 以取得对应的录制 xml


image.png

关闭录制: 

tsung-recorder -L 8888 stop


<users maxnumber="15000" arrivalrate="8" unit="second"/>


Linux压力测试工具Tsung安装、使用和图形报表生成


简介


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

wget http://erlang.org/download/otp_src_20.0.tar.gz
tar -zxvf otp_src_20.0.tar.gz
cd otp_src_20.0
./configure --prefix=/opt/openfire/erlang
make && make install


注意:如果出现 "configure: error: No curses library functions found "错误,尝试安装:

[root@localhost otp_src_20.0]#yum install -y ncurses-devel



2、下载并安装Tsung

wget http://tsung.erlang-projects.org/dist/tsung-1.6.0.tar.gz
tar -zxvf tsung-1.6.0.tar.gz
cd tsung-1.6.0
./configure --prefix=/opt/openfire/tsung --with-erlang=/opt/openfire/erlang/
make && make install



3、下载并安装perl Template,用于生成报告模版


wget --no-check-certificate http://cpan.org/modules/by-module/Template/Template-Toolkit-2.27.tar.gz
tar -zxvf Template-Toolkit-2.27.tar.gz
cd Template-Toolkit-2.27
perl Makefile.PL
make && 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:/opt/openfire/erlang/bin:/opt/openfire/tsung/bin:/opt/openfire/tsung/lib/tsung/bin

export GDFONTPATH="/usr/share/fonts/msttcore"

export GNUPLOT_DEFAULT_GDFONT="arial"


[root@localhost local]# source /etc/profile


[root@localhost local]# tsung -v

Tsung version 1.6.0

[root@localhost openfire]# erl

Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.0  (abort with ^G)





五、使用并生成报表

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  tsung_controller@localhost.log  tsung.log  tsung.xml

4、进入需要生成图形报表的Log目录,如/root/.tsung/log/20150311-0536



[root@localhost 20150311-0536]# /opt/openfire/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  tsung_controller@localhost.log  tsung.log  tsung.xml


5、将report.html拖到windows系统中,直接打开即可查看。



解决:

Could not find/open font when opening font "arial", using internal non-scalable font

http://www.my-guides.net/en/images/stories/fedora12/

http://download.csdn.net/detail/jichl/6856221


安装

#rpm -ivh msttcore-fonts-2.0-3.noarch.rpm

在msttcore的目录路径下即可找到ariali.ttf

设置环境变量

export GDFONTPATH="/usr/share/fonts/msttcore"

export GNUPLOT_DEFAULT_GDFONT="arial"



查看snmp联通:

snmpwalk  -v 2c -c public 139.xxx.xxx.xxx:161 .1.3.6.1.4.1.2021.11.11.0


若没安装, 需要 yum install snmp 安装 一下, 否则无法监控相关负载数据, 可以使用的默认的 public



Load Average 就是一段时间(1min,5min,15min)内平均Load。平均负载的最佳值是1,这意味着每个进程都可以在一个完整的CPU 周期内完成。


性能测试的一些指标

——————————-测试工具中的响应指标(loadrunner、jmeter、tsung等)——————————————–

1.tps(事务每秒处理数)

tps计算工时可以用2 8法则 如活跃用户为100w 则 tps=100w80% / 1820%*3600=61 ps:(18为预估网站一天会有18个小时被人使用)

2.响应时间(并发下的响应时间)

响应时间又分为:

2.1不同页面浏览时候的响应时间

2.2点击注册用户时的响应时间

2.3登录时的响应时间

2.4搜索功能响应时间

2.5项目特殊功能响应时间(可能是demo中暂时没提到的一些特殊功能)

ps:事物的响应时间又分为 最大响应时间、平均响应时间、最小响应时间(验收可忽略此数)、90%响应时间。如为B/S项目 可设定验收标准为 最大响应时间不超过8s、平均响应和90%响应不超过2s。

如为c/s项目(手机客户端)可设定为 最大响应时间不超过10s、平均响应和90%响应不超过4s(因为手机网络相对较慢,可以适当加大响应时间)。

3.测试中事物通过率:

一般web项目通过率为3个9,建议设定验收标注为各个事物通过率为99.9%。

ps:如果后期存在支付购买应用的操作,建议事务通过率设置为9个9 则为99.9999999%,并做重复点击操作测试。

4.性能测试中使用vuser数量

需要先评估上线后会有多少注册用户和活跃用户 比如注册用户数为1000w活跃用户为100w 则vuser计算公式为 C = nL/T C是平均的并发用户数;n是login session的数量(也可以看成是活跃用户数);L是login session的平均长度(一个用户浏览页面到离开 假设为20s);T指考察的时间段长度(可以定义为18小时) 则C=694 在此基础上可以计算出 集合点vuser数为 C’= C+3根号C

5.吞吐量 应与hits tps等数据成正比 且波动较小

以上内存需给出不同测试方法的数据 如压力测试 负载测试 疲劳测试

—————————-服务器运行状况响应指标————————————————————————————

1.cpu% 并发期间最大使用率应不超过80-85%,如有集合点并发可允许短暂接近或到达100& 但大部分不应查过95%

2.memery 测试期间保证内存充足 可用内存不少于20%(入围linux服务器 注意计算cached部分)

2.disk 监控硬盘是否有读写瓶颈

3.cpu load average 不应超过cpu核心数*2或者不超过cpu核心数(此项请op确定吧!)

4.中间件监控 例如使用jetty服务 可使用jconsole或jprofile长期监控确定无内存泄漏

5.测试过程中的db链接数使用情况






/root/.tsung/log/20170824-0025 180s

<users arrivalrate="2" unit="second"></users>


/root/.tsung/log/20170824-0035  180s

<users arrivalrate="10" unit="second"></users>

2362-982 = 1380 单



/root/.tsung/log/20170824-0039

<users arrivalrate="20" unit="second"></users>


982



 /root/.tsung/log/20170824-0051

 浏览首页,列表页,商品详情页,帮助中心页:

<users arrivalrate="20" unit="second"></users>


 /root/.tsung/log/20170824-0056

 <users arrivalrate="50" unit="second"></users>

出现 502 现象, 拒绝服务


压测浏览量:

<? xml version = "1.0"?>
<!DOCTYPE tsung SYSTEM "/opt/openfire/tsung/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" dumptraffic="true" version="1.0">

    <!-- Client side setup -->
    <clients>
        <client host="localhost" use_controller_vm="true" maxusers="60000"/>
    </clients>

    <!-- Server side setup -->
    <servers>
        <server host="10.0.1.11" port="80" type="tcp"></server>
        <!--<server host="www.updateweb.cn" port="80" type="tcp"></server>-->
    </servers>

    <!-- to start os monitoring (cpu, network, memory). Use an erlang
    agent on the remote machine or SNMP. erlang is the default -->

    <monitoring>
        <monitor host="10.0.1.11" type="snmp">
            <snmp version="v2" community="jkbpubc" port="161">
                <oid name="load_average_1" value=".1.3.6.1.4.1.2021.10.1.3.1" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_5" value=".1.3.6.1.4.1.2021.10.1.3.2" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_15" value=".1.3.6.1.4.1.2021.10.1.3.3" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="cpu_idle" value=".1.3.6.1.4.1.2021.11.11.0"></oid>
                <oid name="total_ram_free" value=".1.3.6.1.4.1.2021.4.11.0" eval="fun(X)->X/1024/8 end."></oid>
            </snmp>
        </monitor>
        <monitor host="10.0.3.11" type="snmp">
            <snmp version="v2" community="jkbpubc" port="161">
                <oid name="load_average_1" value=".1.3.6.1.4.1.2021.10.1.3.1" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_5" value=".1.3.6.1.4.1.2021.10.1.3.2" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_15" value=".1.3.6.1.4.1.2021.10.1.3.3" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="cpu_idle" value=".1.3.6.1.4.1.2021.11.11.0"></oid>
                <oid name="total_ram_free" value=".1.3.6.1.4.1.2021.4.11.0" eval="fun(X)->X/1024/8 end."></oid>
            </snmp>
        </monitor>
        <monitor host="10.0.3.12" type="snmp">
            <snmp version="v2" community="jkbpubc" port="161">
                <oid name="load_average_1" value=".1.3.6.1.4.1.2021.10.1.3.1" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_5" value=".1.3.6.1.4.1.2021.10.1.3.2" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_15" value=".1.3.6.1.4.1.2021.10.1.3.3" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="cpu_idle" value=".1.3.6.1.4.1.2021.11.11.0"></oid>
                <oid name="total_ram_free" value=".1.3.6.1.4.1.2021.4.11.0" eval="fun(X)->X/1024/8 end."></oid>
            </snmp>
        </monitor>

    </monitoring>

    <load>
        <!-- several arrival phases can be set: for each phase, you can set
        the mean inter-arrival time between new clients and the phase
        duration -->
        <arrivalphase phase="1" duration="180" unit="second"> <!-- 一阶段 总运行时间30秒-->
            <!--<users interarrival="0.2" unit="second"></users> --><!-- 每秒生成50个虚拟用户-->
            <users arrivalrate="35" unit="second"></users> <!-- 每秒生成50个虚拟用户-->
        </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 JG</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 JG</user_agent>
        </option>
    </options>

    <!-- start a session for a http user. the probability is the
    frequency of this type os session. The sum of all session's
    probabilities must be 100 -->

    <sessions>
        <session name='createorder' probability='100' type='ts_http'>
            <request>
                <http url='http://10.0.1.11/xxx/xxx/' version='1.1' method='GET'></http>
            </request>

            <thinktime random='true' value='2'/>

            <request>
                <http url='http://10.0.1.11/xxx/xxx/brand-17.html' version='1.1' method='GET'></http>
            </request>

            <thinktime random='true' value='4'/>

            <request>
                <http url='http://10.0.1.11/xxx/xxx/content-cat-13.html' version='1.1' method='GET'></http>
            </request>
            <request>
                <http url='http://10.0.1.11/xxx/xxx/content-detail-67.html' version='1.1' method='GET'></http>
            </request>


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


压测试登录与创建订单:

<? xml version = "1.0"?>
<!DOCTYPE tsung SYSTEM "/opt/openfire/tsung/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" dumptraffic="true" version="1.0">

    <!-- Client side setup -->
    <clients>
        <client host="localhost" use_controller_vm="true" maxusers="60000"/>
    </clients>

    <!-- Server side setup -->
    <servers>
        <server host="10.0.1.11" port="80" type="tcp"></server>
        <!--<server host="b2b.com" port="80" type="tcp"></server>-->
    </servers>

    <!-- to start os monitoring (cpu, network, memory). Use an erlang
    agent on the remote machine or SNMP. erlang is the default -->

    <monitoring>
        <monitor host="10.0.1.11" type="snmp">
            <snmp version="v2" community="jkbpubc" port="161">
                <oid name="load_average_1" value=".1.3.6.1.4.1.2021.10.1.3.1" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_5" value=".1.3.6.1.4.1.2021.10.1.3.2" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_15" value=".1.3.6.1.4.1.2021.10.1.3.3" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="cpu_idle" value=".1.3.6.1.4.1.2021.11.11.0"></oid>
                <oid name="total_ram_free" value=".1.3.6.1.4.1.2021.4.11.0" eval="fun(X)->X/1024/8 end."></oid>
            </snmp>
        </monitor>
        <monitor host="10.0.3.11" type="snmp">
            <snmp version="v2" community="jkbpubc" port="161">
                <oid name="load_average_1" value=".1.3.6.1.4.1.2021.10.1.3.1" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_5" value=".1.3.6.1.4.1.2021.10.1.3.2" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_15" value=".1.3.6.1.4.1.2021.10.1.3.3" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="cpu_idle" value=".1.3.6.1.4.1.2021.11.11.0"></oid>
                <oid name="total_ram_free" value=".1.3.6.1.4.1.2021.4.11.0" eval="fun(X)->X/1024/8 end."></oid>
            </snmp>
        </monitor>
        <monitor host="10.0.3.12" type="snmp">
            <snmp version="v2" community="jkbpubc" port="161">
                <oid name="load_average_1" value=".1.3.6.1.4.1.2021.10.1.3.1" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_5" value=".1.3.6.1.4.1.2021.10.1.3.2" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="load_average_15" value=".1.3.6.1.4.1.2021.10.1.3.3" type="sample" eval="fun(X)->list_to_float(X) end."></oid>
                <oid name="cpu_idle" value=".1.3.6.1.4.1.2021.11.11.0"></oid>
                <oid name="total_ram_free" value=".1.3.6.1.4.1.2021.4.11.0" eval="fun(X)->X/1024/8 end."></oid>
            </snmp>
        </monitor>
        <!--  mysql 监控, 没进行实战测试
        <monitor host="garden" type="erlang">
            <mysqladmin port="3306" username="root" />
        </monitor>
        -->
    </monitoring>

    <load>
        <!-- several arrival phases can be set: for each phase, you can set
        the mean inter-arrival time between new clients and the phase
        duration -->
        <arrivalphase phase="1" duration="180" unit="second"> <!-- 一阶段 总运行时间30秒-->
            <!--<users interarrival="0.2" unit="second"></users> --><!-- 每多少s产生一个用户-->
            <users arrivalrate="30" unit="second"></users> <!-- 每s产生多少用户-->
        </arrivalphase>
    </load>

    <options>
        <option name="file_server" id='userdb' value="/root/.tsung/users.csv"/>  
        <option name="file_server" id='productdb' value="/root/.tsung/products.csv"/>
        <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 JG</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 JG</user_agent>
        </option>
    </options>

    <!-- start a session for a http user. the probability is the
    frequency of this type os session. The sum of all session's
    probabilities must be 100 -->

    <sessions>
        <session name='createorder' probability='100' type='ts_http'>
            <setdynvars sourcetype="file" fileid="userdb" delimiter="," order="random">
                <var name="username" />
                <var name="password" />
                <var name="addrid" />
            </setdynvars> 
            <setdynvars sourcetype="file" fileid="productdb" delimiter="," order="random">
                <var name="product_id" />
            </setdynvars> 
            <transaction name="createorder">
                <request  subst="true"><http url='http://xxx.xxx.xxx.xxx:8080/index.php/passport-login.html' version='1.1'  
                contents='LoginForm%5Busername%5D=%%_username%%&amp;LoginForm%5Bpassword%5D=%%_password%%&amp;' content_type='application/x-www-form-urlencoded' method='POST'></http></request>
                <request subst="true"><http url='http://xxx.xxx.xxx.xxx:8080/index.php/member-order-create.html' version='1.1'  
                contents='cart_token=628f5410ae6e2eb9df30886d2111be0b&amp;is_buynow=false&amp;ship_addr_id=%%_addrid%%&amp;
                delivery_id=2&amp;' content_type='application/x-www-form-urlencoded; charset=UTF-8' method='POST'></http></request>
            </transaction>
        </session>
    </sessions>
</tsung>


users.csv

demo,000000,1
test,000000,2


products.csv

60
71
72
73


注意事项:

1. 使用动态变量

a. 随机数方式: 

<setdynvars sourcetype="random_number" start="3" end="100">

    <var name="id" />

</setdynvars>


<request subst="true">

    <http url="/push?id=%%_id%%" version="1.1" method="POST" />

</request>

b. 来自文件,  

options 里添加:   根据情况自定义ID,  

<option name="file_server" id='userdb' value="/root/.tsung/users.csv"/>  

<option name="file_server" id='productdb' value="/root/.tsung/products.csv"/>

注. option里的 sourcetype (random_string | urandom_string | random_number | file | erlang | eval| jsonpath | value | server) 

session 里添加:   定义从文件里取得对应的数据信息, fileid 来自于 option ,  delimiter 即order里定义的分隔字符 

<setdynvars sourcetype="file" fileid="userdb" delimiter="," order="random">

    <var name="username" />

    <var name="password" />

    <var name="addrid" />

</setdynvars> 

<setdynvars sourcetype="file" fileid="productdb" delimiter="," order="random">

    <var name="product_id" />

</setdynvars> 


注意 request 里: 下划线加变量名,并且包含在一对%%中。request必须指定为需要进行动态替换(即subst="true"),否则不会进行动态替换。

 <request  subst="true">

         <http url='http://xxx.xxx.xxx.xxx:8080/passport-login.html' version='1.1'  

               contents='LoginForm%5Busername%5D=%%_username%%&amp;LoginForm%5Bpassword%5D=%%_password%%&amp;' content_type='application/x-www-form-urlencoded' method='POST'></http>

 </request>

c. 来自tsung函数中的随机值

从函数中获取随机内容:

<setdynvars sourcetype="erlang" callback="ts_user_server:get_unique_id">

    <var name="uid" />

</setdynvars>


d. 来自服务器的返回数据: 

来自 header 里的值: 

<request>

    <dyn_variable name="date" header="date" />

    <http url="/test" method="GET" version="1.1" />

</request>

<request subst="true">

    <http url="/home/?date=%%_date%%" method="GET" version="1.1" />

</request>


e. 取得JSON返回值里数据, 作为动态数据: 这里getOrder 请求将返回一个 {"data":{"order_id":1235689}} , subst = "true" 表示启用动态参数 or  field.array[3].value

<request subst="true">   

    <dyn_variable name="orderid" jsonpath="data.order_id"/>  

    <http url="/v10/order/getOrder/" method="POST" version="1.1" contents="token=%%_accesstoken%%data_type=json"/>   

</request>  


f. 从返回的html 里正则出对应的数据做为动态参数, 即从返回的html 正则出对应的订单号值, 作为后续请求的动态参数

<request subst="true">   

    <dyn_variable name="orderid" re="paycenter-(\d+)-true"/>

    <http url="/create-order.php" method="POST" version="1.1" contents="token=%%_accesstoken%%data_type=html" />   

</request>  


2. 判断提交是否成功, 如果不成功则终止后续提交, 类似html里的正则匹配到成功提交的数据, 如下, 如果返回数据里没找到success 则表示终止后续请求 

<request subst="true">   

    <match do="abort" when="nomatch">success</match>

    <dyn_variable name="orderid" re="paycenter-(\d+)-true"/>

    <http url="/create-order.php" method="POST" version="1.1" contents="token=%%_accesstoken%%data_type=html" />   

</request>  


or

<request subst="true">   

    <match do="abort" when="match">error</match>

    <dyn_variable name="orderid" re="paycenter-(\d+)-true"/>

    <http url="/create-order.php" method="POST" version="1.1" contents="token=%%_accesstoken%%data_type=html" />   

</request>  


3. 添加cookie 和 header 等数据: 参考写法

        <http_header name="Accept-Language" value="zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3" />

        <add_cookie key="LANG" value="zh_CN"/>

        <add_cookie key="S[SIGN][REMEMBER]" value="1"/>

        <add_cookie key="UNAME" value="%%_username%%"/>

        <add_cookie key="loginName" value="%%_username%%"/>


其它:

使用正则表达式,XPATH对响应消息的内容进行匹配获取我们所需要的数据。
<request>
    <dyn_variable name="title" xpath="/html/head/title/text()" />
    <http url="/testtsung.html" method="GET" version="1.0" />
</request>
for循环:
<for from="2" to="10" incr="2" var="counter">
    ...
    <request subst="true">
        <http url="/page/?id=%%_counter%%" />
    </request>
    ...
</for>
repeat重复:
<repeat name="myloop" max_repeat="40">
    <request>
        <dyn_variable name="result" re="Result:(.*)" />
        <http url="/random" method="GET" version="1.1" />
    </request>
    ...
    <until var="result" eq="5" />
</repeat>
重复请求/random,返回值保存在result变量中,当返回值内容等于5时,停止请求,最多请求40次。
if判断:
<request>
    <dyn_variable name="result" re="Result: (.*)" />
    <http url="/random" method="GET" version="1.1" />
</request>
<if var="result" eq="3">
    <request><http url="/foo" /></request>
    <request><http url="/bar" /></request>
</if>
如果"/random"请求的结果为3,则再次请求"/foo","/bar"

image.png