环境: 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> |
原文转自:http://blogread.cn/it/article/2974