From bee2ed3c0057d8c7dd05b7696899f06ad2e9bcfd Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Thu, 8 Dec 2016 22:04:55 +0300 Subject: [PATCH] Rafactor select_random_* benchmarks, Refactor select_random_*.lua to reuse code from common.lua. Add basic regression tests. --- sysbench/tests/db/select_random_points.lua | 112 ++------------ sysbench/tests/db/select_random_ranges.lua | 110 ++----------- tests/include/script_select_random_common.sh | 40 +++++ tests/t/script_select_random_mysql.t | 155 +++++++++++++++++++ 4 files changed, 218 insertions(+), 199 deletions(-) create mode 100644 tests/include/script_select_random_common.sh create mode 100644 tests/t/script_select_random_mysql.t diff --git a/sysbench/tests/db/select_random_points.lua b/sysbench/tests/db/select_random_points.lua index 98d9d2a..5f426c8 100644 --- a/sysbench/tests/db/select_random_points.lua +++ b/sysbench/tests/db/select_random_points.lua @@ -4,102 +4,20 @@ -- For details about key_cache_segments please refer to: -- http://kb.askmonty.org/v/segmented-key-cache -- -function prepare() - local query - local i - set_vars() +-- Override oltp_tables_count, this test only supports a single table +oltp_tables_count = 1 - db_connect() +pathtest = string.match(test, "(.*/)") - print("Creating table 'sbtest'...") - - if ((db_driver == "mysql") or (db_driver == "attachsql")) then - query = [[ - CREATE TABLE sbtest ( - id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, - k INTEGER UNSIGNED DEFAULT '0' NOT NULL, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60) DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" - - elseif (db_driver == "oracle") then - query = [[ - CREATE TABLE sbtest ( - id INTEGER NOT NULL, - k INTEGER, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60 DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) ]] - - - elseif (db_driver == "pgsql") then - query = [[ - CREATE TABLE sbtest ( - id ]] .. ((oltp_auto_inc and "SERIAL") or "") .. [[, - k INTEGER DEFAULT '0' NOT NULL, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60) DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) ]] - - elseif (db_driver == "drizzle") then - query = [[ - CREATE TABLE sbtest ( - id INTEGER NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, - k INTEGER DEFAULT '0' NOT NULL, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60) DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) ]] - - else - print("Unknown database driver: " .. db_driver) - return 1 - end - - db_query(query) - - if (db_driver == "oracle") then - db_query("CREATE SEQUENCE sbtest_seq") - db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest - FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) - end - - if oltp_create_secondary then - db_query("CREATE INDEX k on sbtest(k)") - end - - print("Inserting " .. oltp_table_size .. " records into 'sbtest'") - - if (oltp_auto_inc) then - db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") - else - db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") - end - - for i = 1,oltp_table_size do - if (oltp_auto_inc) then - db_bulk_insert_next("("..i..", ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") - else - db_bulk_insert_next("("..i..", "..i..", ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") - end - end - - db_bulk_insert_done() - - return 0 -end - -function cleanup() - print("Dropping table 'sbtest'...") - db_query("DROP TABLE sbtest") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") end function thread_init(thread_id) - set_vars() + set_vars_points() points = "" for i = 1,random_points do @@ -111,7 +29,7 @@ function thread_init(thread_id) stmt = db_prepare([[ SELECT id, k, c, pad - FROM sbtest + FROM sbtest1 WHERE k IN (]] .. points .. [[) ]]) @@ -137,13 +55,7 @@ function event(thread_id) db_free_results(rs) end -function set_vars() - oltp_table_size = oltp_table_size or 10000 - random_points = random_points or 10 - - if (oltp_auto_inc == 'off') then - oltp_auto_inc = false - else - oltp_auto_inc = true - end +function set_vars_points() +set_vars() +random_points = random_points or 10 end diff --git a/sysbench/tests/db/select_random_ranges.lua b/sysbench/tests/db/select_random_ranges.lua index 7f237cc..b67d774 100644 --- a/sysbench/tests/db/select_random_ranges.lua +++ b/sysbench/tests/db/select_random_ranges.lua @@ -4,102 +4,20 @@ -- For details about key_cache_segments please refer to: -- http://kb.askmonty.org/v/segmented-key-cache -- -function prepare() - local query - local i - set_vars() +pathtest = string.match(test, "(.*/)") - db_connect() - - print("Creating table 'sbtest'...") - - if ((db_driver == "mysql") or (db_driver == "attachsql")) then - query = [[ - CREATE TABLE sbtest ( - id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, - k INTEGER UNSIGNED DEFAULT '0' NOT NULL, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60) DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" - - elseif (db_driver == "oracle") then - query = [[ - CREATE TABLE sbtest ( - id INTEGER NOT NULL, - k INTEGER, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60 DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) ]] - - - elseif (db_driver == "pgsql") then - query = [[ - CREATE TABLE sbtest ( - id ]] .. ((oltp_auto_inc and "SERIAL") or "") .. [[, - k INTEGER DEFAULT '0' NOT NULL, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60) DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) ]] - - elseif (db_driver == "drizzle") then - query = [[ - CREATE TABLE sbtest ( - id INTEGER NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, - k INTEGER DEFAULT '0' NOT NULL, - c CHAR(120) DEFAULT '' NOT NULL, - pad CHAR(60) DEFAULT '' NOT NULL, - PRIMARY KEY (id) - ) ]] - - else - print("Unknown database driver: " .. db_driver) - return 1 - end - - db_query(query) - - if (db_driver == "oracle") then - db_query("CREATE SEQUENCE sbtest_seq") - db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest - FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) - end - - if oltp_create_secondary then - db_query("CREATE INDEX k on sbtest(k)") - end - - print("Inserting " .. oltp_table_size .. " records into 'sbtest'") - - if (oltp_auto_inc) then - db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") - else - db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") - end - - for i = 1,oltp_table_size do - if (oltp_auto_inc) then - db_bulk_insert_next("("..i..", ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") - else - db_bulk_insert_next("("..i..", "..i..", ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") - end - end - - db_bulk_insert_done() - - return 0 +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") end -function cleanup() - print("Dropping table 'sbtest'...") - db_query("DROP TABLE sbtest") -end +-- Override oltp_tables_count, this test only supports a single table +oltp_tables_count = 1 function thread_init(thread_id) - set_vars() + set_vars_ranges() ranges = "" for i = 1,number_of_ranges do @@ -111,7 +29,7 @@ function thread_init(thread_id) stmt = db_prepare([[ SELECT count(k) - FROM sbtest + FROM sbtest1 WHERE ]] .. ranges .. [[ ]]) @@ -139,14 +57,8 @@ function event(thread_id) db_free_results(rs) end -function set_vars() - oltp_table_size = oltp_table_size or 10000 +function set_vars_ranges() + set_vars() number_of_ranges = number_of_ranges or 10 delta = random_ranges_delta or 5 - - if (oltp_auto_inc == 'off') then - oltp_auto_inc = false - else - oltp_auto_inc = true - end end diff --git a/tests/include/script_select_random_common.sh b/tests/include/script_select_random_common.sh new file mode 100644 index 0000000..29d6d29 --- /dev/null +++ b/tests/include/script_select_random_common.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# +################################################################################ +# Common code for select_random_* tests +# +# Expects the following variables and callback functions to be defined by the +# caller: +# +# DB_DRIVER_ARGS -- extra driver-specific arguments to pass to sysbench +# +# db_show_table() -- called with a single argument to dump a specified table +# schema +################################################################################ + +set -eu + +for test in select_random_points select_random_ranges +do + ARGS="--test=${SBTEST_SCRIPTDIR}/${test}.lua $DB_DRIVER_ARGS --oltp-tables-count=8" + + sysbench $ARGS prepare + + db_show_table sbtest1 + + for i in $(seq 2 8) + do + db_show_table sbtest${i} || true # Error on non-existing table + done + + sysbench $ARGS --max-requests=100 --num-threads=1 run + + sysbench $ARGS cleanup + + for i in $(seq 1 8) + do + db_show_table sbtest${i} || true # Error on non-existing table + done + + ARGS="--test=${SBTEST_SCRIPTDIR}/select_random_points.lua $DB_DRIVER_ARGS --oltp-tables-count=8" +done diff --git a/tests/t/script_select_random_mysql.t b/tests/t/script_select_random_mysql.t new file mode 100644 index 0000000..9c73abf --- /dev/null +++ b/tests/t/script_select_random_mysql.t @@ -0,0 +1,155 @@ +######################################################################## +select_random_*.lua + MySQL tests +######################################################################## + + $ if [ -z "${SBTEST_MYSQL_ARGS:-}" ] + > then + > exit 80 + > fi + + $ function db_show_table() { + > mysql -uroot sbtest -Nse "SHOW CREATE TABLE $1\G" + > } + + $ DB_DRIVER_ARGS="--db-driver=mysql $SBTEST_MYSQL_ARGS" + $ . $SBTEST_INCDIR/script_select_random_common.sh + sysbench * (glob) + + Creating table 'sbtest1'... + Inserting 10000 records into 'sbtest1' + Creating secondary indexes on 'sbtest1'... + *************************** 1. row *************************** + sbtest1 + CREATE TABLE `sbtest1` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `k` int(10) unsigned NOT NULL DEFAULT '0', + `c` char(120)* NOT NULL DEFAULT '', (glob) + `pad` char(60)* NOT NULL DEFAULT '', (glob) + PRIMARY KEY (`id`), + KEY `k_1` (`k`) + ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob) + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest2' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest3' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest4' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest5' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest6' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest7' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest8' doesn't exist + sysbench * (glob) + + Running the test with following options: + Number of threads: 1 + Initializing random number generator from current time + + + Initializing worker threads... + + Threads started! + + OLTP test statistics: + queries performed: + read: 100 + write: 0 + other: 0 + total: 100 + transactions: 0 (0.00 per sec.) + read/write requests: 100 (* per sec.) (glob) + other operations: 0 (0.00 per sec.) + ignored errors: 0 (0.00 per sec.) + reconnects: 0 (0.00 per sec.) + + General statistics: + total time: *s (glob) + total number of events: 100 + total time taken by event execution: *s (glob) + response time: + min:* (glob) + avg:* (glob) + max:* (glob) + approx.* (glob) + + Threads fairness: + events (avg/stddev):* (glob) + execution time (avg/stddev):* (glob) + + sysbench * (glob) + + Dropping table 'sbtest1'... + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest1' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest2' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest3' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest4' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest5' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest6' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest7' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest8' doesn't exist + sysbench * (glob) + + Creating table 'sbtest1'... + Inserting 10000 records into 'sbtest1' + Creating secondary indexes on 'sbtest1'... + *************************** 1. row *************************** + sbtest1 + CREATE TABLE `sbtest1` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `k` int(10) unsigned NOT NULL DEFAULT '0', + `c` char(120)* NOT NULL DEFAULT '', (glob) + `pad` char(60)* NOT NULL DEFAULT '', (glob) + PRIMARY KEY (`id`), + KEY `k_1` (`k`) + ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob) + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest2' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest3' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest4' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest5' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest6' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest7' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest8' doesn't exist + sysbench * (glob) + + Running the test with following options: + Number of threads: 1 + Initializing random number generator from current time + + + Initializing worker threads... + + Threads started! + + OLTP test statistics: + queries performed: + read: 100 + write: 0 + other: 0 + total: 100 + transactions: 0 (0.00 per sec.) + read/write requests: 100 (* per sec.) (glob) + other operations: 0 (0.00 per sec.) + ignored errors: 0 (0.00 per sec.) + reconnects: 0 (0.00 per sec.) + + General statistics: + total time: *s (glob) + total number of events: 100 + total time taken by event execution: *s (glob) + response time: + min:* (glob) + avg:* (glob) + max:* (glob) + approx.* (glob) + + Threads fairness: + events (avg/stddev):* (glob) + execution time (avg/stddev):* (glob) + + sysbench * (glob) + + Dropping table 'sbtest1'... + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest1' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest2' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest3' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest4' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest5' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest6' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest7' doesn't exist + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest8' doesn't exist