下面是insert.lua脚本的内容:
[root@pxc-control ~]# cat /usr/share/doc/sysbench/tests/db/insert.lua
pathtest = string.match(test, "(.*/)") or ""
dofile(pathtest .. "common.lua")
function thread_init(thread_id)
set_vars()
end
function event(thread_id)
local table_name
local i
local c_val
local k_val
local pad_val
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
if (oltp_auto_inc) then
i = 0
else
i = sb_rand_uniq(1, oltp_table_size)
end
k_val = sb_rand(1, oltp_table_size)
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
rs = db_query("INSERT INTO " .. table_name .. " (id, k, c, pad) VALUES " .. string.format("(%d, %d, '%s', '%s')",i, k_val, c_val, pad_val))
end
我比较喜欢sysbench 0.5的一个地方(超过lua 接口,肯定的!)是它现在带来一个配置项–report-interval option(我通常都是设置为 =1),以便在脚本运行时你可以定时看到输出信息。不要等到运行结束是再得到反馈!这里有个用sysbench 0.5的测试样例,通过本地hapoxy实例运行插入数据动作以及向在同一个PXC(Percona XtrDB Cluster)集群上的三个节点写数据动作,例如OpenStack Trove会做:
[root@pxc-control ~]# ./sys_haproxy.sh run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 3
Report intermediate results every 1 second(s)
Random number generator seed is 0 and will be ignored
Threads started!
[ 1s] threads: 3, tps: 0.00, reads/s: 0.00, writes/s: 1099.28, response time: 9.86ms (95%)
[ 2s] threads: 3, tps: 0.00, reads/s: 0.00, writes/s: 973.02, response time: 10.77ms (95%)
[ 3s] threads: 3, tps: 0.00, reads/s: 0.00, writes/s: 1181.01, response time: 6.23ms (95%)
[ 4s] threads: 3, tps: 0.00, reads/s: 0.00, writes/s: 1103.00, response time: 6.77ms (95%)
我也想让你注意到来自Nilnandan Joshi博客的文章,Nilnandan Joshi是来自Percona支持团队,在这篇文章中他介绍了在Debian 7上编译构建sysbench 0.5的一种方法。在这里非常感谢Nil的贡献!
我希望这篇文章可以帮组那些想要升级到sysbench 0.5的同志,并且能质疑(探讨)-test=oltp去哪儿了。我很乐意看到你自己的关于sysbench用户案列,并且是否有其他人发布过他们自己的用于负载测试的lua脚本!