Parallel 'prepare' and 'prewarm' (MySQL-only) commands for OLTP benchmarks.
This commit is contained in:
@ -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()
|
||||
|
||||
10
src/sb_lua.c
10
src/sb_lua.c
@ -1348,6 +1348,9 @@ static bool sb_lua_custom_command_parallel(const char *name)
|
||||
|
||||
static int call_custom_command(lua_State *L)
|
||||
{
|
||||
if (export_options(L))
|
||||
return 1;
|
||||
|
||||
lua_getglobal(L, "sysbench");
|
||||
lua_getfield(L, -1, "cmdline");
|
||||
lua_getfield(L, -1, "call_command");
|
||||
@ -1365,7 +1368,7 @@ static int call_custom_command(lua_State *L)
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0) != 0)
|
||||
{
|
||||
call_error(L, "sysbench.cmdline.command_defined");
|
||||
call_error(L, "sysbench.cmdline.call_command");
|
||||
lua_pop(L, 2);
|
||||
return 1;
|
||||
}
|
||||
@ -1384,6 +1387,9 @@ static void *cmd_worker_thread(void *arg)
|
||||
|
||||
sb_tls_thread_id = ctxt->id;
|
||||
|
||||
/* Initialize thread-local RNG state */
|
||||
sb_rand_thread_init();
|
||||
|
||||
lua_State * const L = sb_lua_new_state();
|
||||
|
||||
if (L == NULL)
|
||||
@ -1405,7 +1411,7 @@ int sb_lua_call_custom_command(const char *name)
|
||||
{
|
||||
sb_lua_custom_command = name;
|
||||
|
||||
if (sb_lua_custom_command_parallel(name))
|
||||
if (sb_lua_custom_command_parallel(name) && sb_globals.num_threads > 1)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
||||
@ -29,6 +29,8 @@ db_show_table sbtest7
|
||||
db_show_table sbtest8
|
||||
db_show_table sbtest9 || true # Error on non-existing table
|
||||
|
||||
sysbench $ARGS prewarm || true # MySQL only
|
||||
|
||||
sysbench $ARGS --max-requests=100 --num-threads=2 run
|
||||
|
||||
sysbench $ARGS cleanup
|
||||
|
||||
@ -112,6 +112,16 @@ oltp_point_select.lua + MySQL tests
|
||||
KEY `k_8` (`k`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* (glob)
|
||||
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest9' doesn't exist
|
||||
sysbench * (glob)
|
||||
|
||||
Prewarming table sbtest1
|
||||
Prewarming table sbtest2
|
||||
Prewarming table sbtest3
|
||||
Prewarming table sbtest4
|
||||
Prewarming table sbtest5
|
||||
Prewarming table sbtest6
|
||||
Prewarming table sbtest7
|
||||
Prewarming table sbtest8
|
||||
sysbench *.* * (glob)
|
||||
|
||||
Running the test with following options:
|
||||
|
||||
@ -122,6 +122,9 @@ oltp_point_select.lua + PostgreSQL tests
|
||||
Did not find any relation named "sbtest9".
|
||||
sysbench *.* * (glob)
|
||||
|
||||
FATAL: *: prewarm is currently MySQL only (glob)
|
||||
sysbench *.* * (glob)
|
||||
|
||||
Running the test with following options:
|
||||
Number of threads: 2
|
||||
Initializing random number generator from current time
|
||||
|
||||
@ -112,6 +112,16 @@ oltp_point_select.lua + MySQL tests
|
||||
KEY `k_8` (`k`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* (glob)
|
||||
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest9' doesn't exist
|
||||
sysbench * (glob)
|
||||
|
||||
Prewarming table sbtest1
|
||||
Prewarming table sbtest2
|
||||
Prewarming table sbtest3
|
||||
Prewarming table sbtest4
|
||||
Prewarming table sbtest5
|
||||
Prewarming table sbtest6
|
||||
Prewarming table sbtest7
|
||||
Prewarming table sbtest8
|
||||
sysbench *.* * (glob)
|
||||
|
||||
Running the test with following options:
|
||||
|
||||
@ -122,6 +122,9 @@ oltp_point_select.lua + PostgreSQL tests
|
||||
Did not find any relation named "sbtest9".
|
||||
sysbench *.* * (glob)
|
||||
|
||||
FATAL: *: prewarm is currently MySQL only (glob)
|
||||
sysbench *.* * (glob)
|
||||
|
||||
Running the test with following options:
|
||||
Number of threads: 2
|
||||
Initializing random number generator from current time
|
||||
|
||||
@ -113,6 +113,16 @@ oltp_read_write.lua + MySQL tests
|
||||
KEY `k_8` (`k`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* (glob)
|
||||
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest9' doesn't exist
|
||||
sysbench * (glob)
|
||||
|
||||
Prewarming table sbtest1
|
||||
Prewarming table sbtest2
|
||||
Prewarming table sbtest3
|
||||
Prewarming table sbtest4
|
||||
Prewarming table sbtest5
|
||||
Prewarming table sbtest6
|
||||
Prewarming table sbtest7
|
||||
Prewarming table sbtest8
|
||||
sysbench *.* * (glob)
|
||||
|
||||
Running the test with following options:
|
||||
@ -294,6 +304,16 @@ oltp_read_write.lua + MySQL tests
|
||||
KEY `k_8` (`k`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* (glob)
|
||||
ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest9' doesn't exist
|
||||
sysbench * (glob)
|
||||
|
||||
Prewarming table sbtest1
|
||||
Prewarming table sbtest2
|
||||
Prewarming table sbtest3
|
||||
Prewarming table sbtest4
|
||||
Prewarming table sbtest5
|
||||
Prewarming table sbtest6
|
||||
Prewarming table sbtest7
|
||||
Prewarming table sbtest8
|
||||
sysbench *.* * (glob)
|
||||
|
||||
Running the test with following options:
|
||||
|
||||
@ -122,6 +122,9 @@ oltp_read_write.lua + PostgreSQL tests
|
||||
Did not find any relation named "sbtest9".
|
||||
sysbench *.* * (glob)
|
||||
|
||||
FATAL: *: prewarm is currently MySQL only (glob)
|
||||
sysbench *.* * (glob)
|
||||
|
||||
Running the test with following options:
|
||||
Number of threads: 2
|
||||
Initializing random number generator from current time
|
||||
|
||||
Reference in New Issue
Block a user