Rafactor select_random_* benchmarks,

Refactor select_random_*.lua to reuse code from common.lua. Add basic
regression tests.
This commit is contained in:
Alexey Kopytov
2016-12-08 22:04:55 +03:00
parent b5a759fd76
commit bee2ed3c00
4 changed files with 218 additions and 199 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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