有时候我们需要完全模拟生产数据库的负载,需要自定义提供SQL语句,绑定变量采样的方法和各个语句执行的百分比,以便真实还原生产数据库在目标机器的压力情况。由于不方便使用一些带GUI的压力测试工具,所以自己写了一个基于JDBC,java多线程的handy tool-- 【HAOTPS】。下载地址:http://space.itpub.net/15415488/viewspace-674358目前share出来的是beta2版,不带我们自己环境的一些特殊需求,仅仅保留最原始的显示average TPS和average response time的结果。这个工具,根据你提供的一个配置文件作为输入参数。这个可以从下载下来的zip包中的test.conf修改。test.conf如下:######### Author: Hao Zhu
######### When : 2010-09
######### This file is used to feed the HAOTPS java program
######### beta2 version#################################################################
#Connection String Part provide the connection string of target database
#################################################################
^^^Connection String Part^^^#hostname can be the IP of the target host
$hostname = xxx.xxx.xxx.xxx$port = 1521#sid is the ORACLE_SID of the target database
$sid = mysid #username and password are used to logon to the target database
$username = hao
$password = hao#thread means how many client threads will be started
$thread = 40#query_cnt_per_thread means how many queries will be run in one single thread
$query_cnt_per_thread = 100000#################################################################
#SQL part are the SQLs you want to use to generate the load on target
#################################################################
^^^SQL Part^^^#Totally how many SQLs will be supplied in the file
$sql_count=2
--------------------------
#the percent of executions among all sqls(please remember that the sum of sql_percent should be 100!!!)
$sql_percent=50#SQL_TEXT, as you know
$sql_text=
select count(*) from testbyhao
where object_name=?#how many bind variables(please count for the "?" in above sql_text
)
$bind_variables_count=1#bind number in "Bind Variables Sample Part":
$bind_1=1
--------------------------
$sql_percent=50
$sql_text=
select count(*) from testbyhao
where object_id=?$bind_variables_count=1
$bind_1=2#################################################################
#Bind variables sample part will feed the bind var for above SQLs
#################################################################
^^^Bind Variables Sample Part^^^
--------------------------
#bind_number is the unique key of all the binds starting with 1 incremental by 1:
$bind_number=1#bind_type is the data type, currently I only suppport int and string:
$bind_type=string#bind_sample_sql is the SQL to fetch the sample data and store it in memory when HAOTPS is running:
$bind_sample_sql=
select object_name from testbyhao sample(99.99)
where rownum<=1000
--------------------------
$bind_number=2
$bind_type=int
$bind_sample_sql=
select object_id from testbyhao sample(99.99)
where rownum<=1000
我简单的解释一下这个文件,第一部分提供的是连接字符串部分。第二部分是你提供的SQL语句部分,其中每个SQL的绑定变量部分是指向的是第三部分(绑定变量部分)。例如“$bind_1=1”是指,这个sql的第1个绑定变量引用的第三部分中的“$bind_number=1”的这个绑定变量。这样多个SQL可以share同一个绑定变量。第三部分就是绑定变量部分,告诉我们绑定变量是通过什么SQL采样得到的。当执行的时候,第三部分采样的结果就放在内存里,供第二部分的SQL随机取一个来用。这个很简单的例子输出为:cmd line>java haotps test.conf
======1.checking the config file test.conf ......
======2.checking constraint of the config ......
======3.collecting all the bind variable data ......
======4.running 40 threads, each thread with 100000 queries......
----------------Result--------------
Average response time(ms) = 0.667
Average TPS = 58380.52
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15415488/viewspace-674362/
,如需转载,请注明出处,否则将追究法律责任。