Tsung为MySQL服务器进行压力测试的脚本
作者:网络转载 发布时间:[ 2013/10/24 10:38:55 ] 推荐标签:
这个MySQL服务器压测的需求是 :
环境: Linux RHEL 5U4 X86-64, 24G内存, 16核.
MySQL服务器在10.232.36.100上。
压力由多32个客户端发起,每个客户端分别做update, insert, delete操作,概率分别是50%, 30%, 20%, 每种操作循环999999 × 100次,每100次操作后休息1-3秒。
这样的压力多持续2个小时。
我们用的是的tsung压力测试工具, 之前我有篇blog介绍过, 见这里。
以下是用到的脚本, 用到了比较先进的随机动态参数替换等技术,对于编写此类脚本有很大的借鉴意义。
以下是代码片段:
<!DOCTYPE tsung SYSTEM "/usr/local/share/tsung/tsung-1.0.dtd">
<tsung loglevel="warning" dumptraffic="false">
<clients>
<client host="localhost" use_controller_vm="true"/>
</clients>
<servers>
<server host="10.232.36.100" port="3306" type="tcp"/>
</servers>
<load>
<arrivalphase phase="1" duration="2" unit="hour">
<users interarrival="0.1" unit="second" maxnumber="32"></users>
</arrivalphase>
</load>
<sessions>
<session probability="50" name="st-replace" type="ts_mysql">
<request>
<mysql type="connect" />
</request>
<request>
<mysql type="authenticate" database="test" username="test" password="mysqltest" />
</request>
<for from="1" to="999999" var="counter">
<for from="1" to="100" var="counter">
<setdynvars sourcetype="random_number" start="1" end="999999999">
<var name="rnd_uid" />
</setdynvars>
<setdynvars sourcetype="random_string" length="13">
<var name="rnd_uname" />
</setdynvars>
<setdynvars sourcetype="random_number" start="0" end="1">
<var name="rnd_male" />
</setdynvars>
<setdynvars sourcetype="random_number" start="1" end="120">
<var name="rnd_age" />
</setdynvars>
<setdynvars sourcetype="random_string" length="10">
<var name="rnd_city" />
</setdynvars>
<setdynvars sourcetype="random_string" length="52">
<var name="rnd_profile" />
</setdynvars>
<request subst="true">
<mysql type="sql">replace into user(tid, uname, male, age, city, profile) values(%%_rnd_uid%%, "%%_rnd_uname%%", %%_rnd_male%%, %%_rnd_age%%, "%%_rnd_city%%", "%%_rnd_profile%%") </mysql>
</request>
</for>
<thinktime min="2" max="5" random="true" />
</for>
<request>
<mysql type="close"></mysql>
</request>
</session>
<session probability="20" name="st-delete" type="ts_mysql">
<request>
<mysql type="connect" />
</request>
<request>
<mysql type="authenticate" database="test" username="test" password="mysqltest" />
</request>
<for from="1" to="999999" var="counter">
<for from="1" to="100" var="counter">
<setdynvars sourcetype="random_number" start="1" end="999999999">
<var name="rnd_uid" />
</setdynvars>
<request subst="true">
<mysql type="sql">delete from user where tid = %%_rnd_uid%% </mysql>
</request>
</for>
<thinktime min="2" max="5" random="true" />
</for>
<request>
<mysql type="close"></mysql>
</request>
</session>
<session probability="30" name="st-update" type="ts_mysql">
<request>
<mysql type="connect" />
</request>
<request>
<mysql type="authenticate" database="test" username="test" password="mysqltest" />
</request>
<for from="1" to="999999" var="counter">
<for from="1" to="100" var="counter">
<setdynvars sourcetype="random_number" start="1" end="999999999">
<var name="rnd_uid" />
</setdynvars>
<setdynvars sourcetype="random_string" length="52">
<var name="rnd_profile" />
</setdynvars>
<request subst="true">
<mysql type="sql">update user set profile = "%%_rnd_profile%%" where tid = %%_rnd_uid%% </mysql>
</request>
</for>
<thinktime min="2" max="5" random="true" />
</for>
<request>
<mysql type="close"></mysql>
</request>
</session>
</sessions>
</tsung>
祝压测开心!
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11