This is a follow-up on my previous blog post about using Lua enabled sysbench. Today I will dive into how to write Lua scripts for sysbench. Look at this simple example:
function prepare ()
local i
print("creating table sbtest.t1 ...")
db_query("create table t1 (c1 int unsigned primary key, c2 int)")
db_query("begin")
for i= 1, 1000 do
db_query("insert into t1 values (" .. i .. "," .. i .. ")")
end
db_query("commit")
end
function cleanup()
db_query("drop table t1")
end
function help()
print("sysbench Lua demo; no special command line options available")
end
function thread_init(thread_id)
end
function thread_done(thread_id)
db_disconnect()
end
function event(thread_id)
db_query("select c2 from t1 where c1=" .. sb_rand(1, 1000))
end
There are 3 functions prepare(),
cleanup() and help(). Those are …