diff --git a/sysbench/lua/Makefile.am b/sysbench/lua/Makefile.am index 99cba89..f15ab59 100644 --- a/sysbench/lua/Makefile.am +++ b/sysbench/lua/Makefile.am @@ -16,6 +16,7 @@ SUBDIRS = internal -dist_pkgdata_DATA = oltp_common.lua oltp.lua \ +dist_pkgdata_DATA = bulk_insert.lua \ + oltp_common.lua oltp.lua \ oltp_point_select.lua \ select_random_points.lua select_random_ranges.lua diff --git a/sysbench/lua/bulk_insert.lua b/sysbench/lua/bulk_insert.lua new file mode 100644 index 0000000..0143247 --- /dev/null +++ b/sysbench/lua/bulk_insert.lua @@ -0,0 +1,54 @@ +-- -------------------------------------------------------------------------- -- +-- Bulk insert benchmark: do multi-row INSERTs concurrently in --num-threads +-- threads with each thread inserting into its own table. The number of INSERTs +-- executed by each thread is controlled by either --max-time or --max-requests. +-- -------------------------------------------------------------------------- -- + +cursize=0 + +function thread_init() + drv = sysbench.sql.driver() + con = drv:connect() +end + +function prepare() + local i + + local drv = sysbench.sql.driver() + local con = drv:connect() + + for i = 1, num_threads do + print("Creating table 'sbtest" .. i .. "'...") + con:query(string.format([[ + CREATE TABLE IF NOT EXISTS sbtest%d ( + id INTEGER NOT NULL, + k INTEGER DEFAULT '0' NOT NULL, + PRIMARY KEY (id))]], i)) + end +end + +function event() + if (cursize == 0) then + con:bulk_insert_init("INSERT INTO sbtest" .. thread_id+1 .. " VALUES") + end + + cursize = cursize + 1 + + con:bulk_insert_next("(" .. cursize .. "," .. cursize .. ")") +end + +function thread_done(thread_9d) + con:bulk_insert_done() +end + +function cleanup() + local i + + local drv = sysbench.sql.driver() + local con = drv:connect() + + for i = 1, num_threads do + print("Dropping table 'sbtest" .. i .. "'...") + con:query("DROP TABLE IF EXISTS sbtest" .. i ) + end +end diff --git a/tests/include/script_bulk_insert_common.sh b/tests/include/script_bulk_insert_common.sh new file mode 100644 index 0000000..21b0a93 --- /dev/null +++ b/tests/include/script_bulk_insert_common.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# +################################################################################ +# Common code for select_bulk_insert* 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 + +ARGS="--test=${SBTEST_SCRIPTDIR}/bulk_insert.lua $DB_DRIVER_ARGS --num-threads=2 --verbosity=1" + +sysbench $ARGS prepare + +for i in $(seq 1 3) +do + db_show_table sbtest${i} || true # Error on non-existing table +done + +sysbench $ARGS --max-requests=100 --verbosity=3 run + +sysbench $ARGS cleanup + +for i in $(seq 1 3) +do + db_show_table sbtest${i} || true # Error on non-existing table +done diff --git a/tests/t/script_bulk_insert_mysql.t b/tests/t/script_bulk_insert_mysql.t new file mode 100644 index 0000000..3e8b78e --- /dev/null +++ b/tests/t/script_bulk_insert_mysql.t @@ -0,0 +1,74 @@ +######################################################################## +bulk_insert.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_bulk_insert_common.sh + Creating table 'sbtest1'... + Creating table 'sbtest2'... + *************************** 1. row *************************** + sbtest1 + CREATE TABLE `sbtest1` ( + `id` int(11) NOT NULL, + `k` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) + ) ENGINE=InnoDB * (glob) + *************************** 1. row *************************** + sbtest2 + CREATE TABLE `sbtest2` ( + `id` int(11) NOT NULL, + `k` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) + ) ENGINE=InnoDB * (glob) + ERROR 1146 (42S02) at line 1: Table 'sbtest.sbtest3' doesn't exist + sysbench * (glob) + + Running the test with following options: + Number of threads: 2 + Initializing random number generator from current time + + + Initializing worker threads... + + Threads started! + + OLTP test statistics: + queries performed: + read: 0 + write: 2 + other: 0 + total: 2 + transactions: 100 (* per sec.) (glob) + queries: 2 (* per sec.) (glob) + 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) + + Latency statistics: + min: *.*ms (glob) + avg: *.*ms (glob) + max: *.*ms (glob) + approx. 95th percentile: *.*ms (glob) + + Threads fairness: + events (avg/stddev):* (glob) + execution time (avg/stddev):* (glob) + + Dropping table 'sbtest1'... + Dropping table 'sbtest2'... + 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 diff --git a/tests/t/script_bulk_insert_pgsql.t b/tests/t/script_bulk_insert_pgsql.t new file mode 100644 index 0000000..8d7971c --- /dev/null +++ b/tests/t/script_bulk_insert_pgsql.t @@ -0,0 +1,76 @@ +######################################################################## +bulk_insert.lua + PostgreSQL tests +######################################################################## + + $ if [ -z "${SBTEST_PGSQL_ARGS:-}" ] + > then + > exit 80 + > fi + + $ function db_show_table() { + > psql -c "\d+ $1" sbtest + > } + + $ DB_DRIVER_ARGS="--db-driver=pgsql $SBTEST_PGSQL_ARGS" + $ . $SBTEST_INCDIR/script_bulk_insert_common.sh + Creating table 'sbtest1'... + Creating table 'sbtest2'... + Table "public.sbtest1" + Column | Type | Modifiers | Storage | Stats target | Description + --------+---------+--------------------+---------+--------------+------------- + id | integer | not null | plain | | + k | integer | not null default 0 | plain | | + Indexes: + "sbtest1_pkey" PRIMARY KEY, btree (id) + + Table "public.sbtest2" + Column | Type | Modifiers | Storage | Stats target | Description + --------+---------+--------------------+---------+--------------+------------- + id | integer | not null | plain | | + k | integer | not null default 0 | plain | | + Indexes: + "sbtest2_pkey" PRIMARY KEY, btree (id) + + Did not find any relation named "sbtest3". + sysbench * (glob) + + Running the test with following options: + Number of threads: 2 + Initializing random number generator from current time + + + Initializing worker threads... + + Threads started! + + OLTP test statistics: + queries performed: + read: 0 + write: 2 + other: 0 + total: 2 + transactions: 100 (* per sec.) (glob) + queries: 2 (* per sec.) (glob) + 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) + + Latency statistics: + min: *.*ms (glob) + avg: *.*ms (glob) + max: *.*ms (glob) + approx. 95th percentile: *.*ms (glob) + + Threads fairness: + events (avg/stddev):* (glob) + execution time (avg/stddev):* (glob) + + Dropping table 'sbtest1'... + Dropping table 'sbtest2'... + Did not find any relation named "sbtest1". + Did not find any relation named "sbtest2". + Did not find any relation named "sbtest3".