Parallel 'prepare' and 'prewarm' (MySQL-only) commands for OLTP benchmarks.

This commit is contained in:
Alexey Kopytov
2017-01-28 17:55:29 +03:00
parent 49aa0b4322
commit 12e56538f3
9 changed files with 111 additions and 12 deletions

View File

@ -71,6 +71,57 @@ sysbench.option_defs = {
"delete_inserts is set to 0"}
}
-- Prepare the dataset. This command support parallel execution, i.e. will
-- benefit from executing with --num-threads > 1 as long as --tables > 1
function cmd_prepare()
local drv = sysbench.sql.driver()
local con = drv:connect()
for i = sysbench.tid % sysbench.opt.num_threads + 1, sysbench.opt.tables,
sysbench.opt.num_threads do
create_table(drv, con, i)
end
end
-- Preload the dataset into the server cache. This command support parallel
-- execution, i.e. will benefit from executing with --num-threads > 1 as long as
-- --tables > 1
--
-- PS. Currently, this command is only meaningful for MySQL/InnoDB benchmarks
function cmd_prewarm()
local drv = sysbench.sql.driver()
local con = drv:connect()
assert(drv:name() == "mysql", "prewarm is currently MySQL only")
-- Do not create on disk tables for subsequent queries
con:query("SET tmp_table_size=2*1024*1024*1024")
con:query("SET max_heap_table_size=2*1024*1024*1024")
for i = sysbench.tid % sysbench.opt.num_threads + 1, sysbench.opt.tables,
sysbench.opt.num_threads do
local t = "sbtest" .. i
print("Prewarming table " .. t)
con:query("ANALYZE TABLE sbtest" .. i)
con:query(string.format(
"SELECT AVG(id) FROM " ..
"(SELECT * FROM %s FORCE KEY (PRIMARY) " ..
"LIMIT %u) t",
t, sysbench.opt.table_size))
con:query(string.format(
"SELECT COUNT(*) FROM " ..
"(SELECT * FROM %s WHERE k LIKE '%%0%%' LIMIT %u) t",
t, sysbench.opt.table_size))
end
end
-- Implement parallel prepare and prewarm commands
sysbench.cmdline.commands = {
prepare = {cmd_prepare, sysbench.cmdline.PARALLEL_COMMAND},
prewarm = {cmd_prewarm, sysbench.cmdline.PARALLEL_COMMAND}
}
-- Generate strings of random digits with 11-digit groups separated by dashes
function get_c_value()
-- 10 groups, 119 characters
@ -86,7 +137,7 @@ function get_pad_value()
"###########-###########")
end
local function create_table(drv, con, table_num)
function create_table(drv, con, table_num)
local id_index_def, id_def
local engine_def = ""
local extra_table_options = ""
@ -300,15 +351,6 @@ function thread_init()
prepare_statements()
end
function prepare()
local drv = sysbench.sql.driver()
local con = drv:connect()
for i = 1, sysbench.opt.tables do
create_table(drv, con, i)
end
end
function cleanup()
local drv = sysbench.sql.driver()
local con = drv:connect()