From 352788cc13892f6307c35b7d00c97b2394429841 Mon Sep 17 00:00:00 2001 From: Robins Tharakan Date: Mon, 5 Dec 2016 10:23:39 +0000 Subject: [PATCH 1/8] select_random_xx should honour oltp_secondary_create, just like other tests --- sysbench/tests/db/select_random_points.lua | 4 +++- sysbench/tests/db/select_random_ranges.lua | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sysbench/tests/db/select_random_points.lua b/sysbench/tests/db/select_random_points.lua index 66f5961..98d9d2a 100644 --- a/sysbench/tests/db/select_random_points.lua +++ b/sysbench/tests/db/select_random_points.lua @@ -68,7 +68,9 @@ function prepare() FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) end - db_query("CREATE INDEX k on sbtest(k)") + if oltp_create_secondary then + db_query("CREATE INDEX k on sbtest(k)") + end print("Inserting " .. oltp_table_size .. " records into 'sbtest'") diff --git a/sysbench/tests/db/select_random_ranges.lua b/sysbench/tests/db/select_random_ranges.lua index 8da50b1..7f237cc 100644 --- a/sysbench/tests/db/select_random_ranges.lua +++ b/sysbench/tests/db/select_random_ranges.lua @@ -68,7 +68,9 @@ function prepare() FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) end - db_query("CREATE INDEX k on sbtest(k)") + if oltp_create_secondary then + db_query("CREATE INDEX k on sbtest(k)") + end print("Inserting " .. oltp_table_size .. " records into 'sbtest'") From 396698aadf9d94c873669f4d1b3cfa1146dfcc8e Mon Sep 17 00:00:00 2001 From: Robins Tharakan Date: Mon, 5 Dec 2016 10:56:17 +0000 Subject: [PATCH 2/8] Adding --pgsql-variant=redshift argument targets a Redshift DB --- sysbench/tests/db/common.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sysbench/tests/db/common.lua b/sysbench/tests/db/common.lua index 1677dc4..5d9be23 100644 --- a/sysbench/tests/db/common.lua +++ b/sysbench/tests/db/common.lua @@ -17,6 +17,12 @@ function create_insert(table_id) index_name = "PRIMARY KEY" end + if (pgsql_variant == 'redshift') then + auto_inc_type = "INTEGER IDENTITY(1,1)" + else + auto_inc_type = "SERIAL" + end + i = table_id print("Creating table 'sbtest" .. i .. "'...") @@ -36,7 +42,7 @@ pad CHAR(60) DEFAULT '' NOT NULL, elseif (db_driver == "pgsql") then query = [[ CREATE TABLE sbtest]] .. i .. [[ ( -id SERIAL NOT NULL, +id ]] .. auto_inc_type .. [[ NOT NULL, k INTEGER DEFAULT '0' NOT NULL, c CHAR(120) DEFAULT '' NOT NULL, pad CHAR(60) DEFAULT '' NOT NULL, @@ -176,4 +182,9 @@ function set_vars() oltp_create_secondary = true end + if (pgsql_variant == 'redshift') then + oltp_create_secondary = false + oltp_delete_inserts = 0 + end + end From aead4b99bd6c4d55292c15a49c932c51f9c51556 Mon Sep 17 00:00:00 2001 From: Robins Tharakan Date: Mon, 5 Dec 2016 12:23:46 +0000 Subject: [PATCH 3/8] Minor change to ensure all existing tests pass after previous commit --- tests/t/drivers.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/t/drivers.t b/tests/t/drivers.t index 6eaf6db..943b8ee 100644 --- a/tests/t/drivers.t +++ b/tests/t/drivers.t @@ -18,5 +18,5 @@ Make sure all available DB drivers are covered Dropping table 'sbtest1'... FATAL: invalid database driver name: 'nonexisting' - FATAL: failed to execute function `cleanup': */common.lua:122: DB initialization failed (glob) + FATAL: failed to execute function `cleanup': */common.lua:128: DB initialization failed (glob) [1] From bee2ed3c0057d8c7dd05b7696899f06ad2e9bcfd Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Thu, 8 Dec 2016 22:04:55 +0300 Subject: [PATCH 4/8] 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 From c36861f5ad56b79ba32056759bc5efb4a47c1296 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Thu, 8 Dec 2016 22:31:06 +0300 Subject: [PATCH 5/8] Add PostgreSQL tests for select_random_*.lua --- tests/t/script_select_random_pgsql.t | 157 +++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 tests/t/script_select_random_pgsql.t diff --git a/tests/t/script_select_random_pgsql.t b/tests/t/script_select_random_pgsql.t new file mode 100644 index 0000000..49761c9 --- /dev/null +++ b/tests/t/script_select_random_pgsql.t @@ -0,0 +1,157 @@ +######################################################################## +select_random_*.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_select_random_common.sh + sysbench 1.0: multi-threaded system evaluation benchmark + + Creating table 'sbtest1'... + Inserting 10000 records into 'sbtest1' + Creating secondary indexes on 'sbtest1'... + Table "public.sbtest1" + Column | Type | Modifiers | Storage | Stats target | Description + --------+----------------+------------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('sbtest1_id_seq'::regclass) | plain | | + k | integer | not null default 0 | plain | | + c | character(120) | not null default ''::bpchar | extended | | + pad | character(60) | not null default ''::bpchar | extended | | + Indexes: + "sbtest1_pkey" PRIMARY KEY, btree (id) + "k_1" btree (k) + + Did not find any relation named "sbtest2". + Did not find any relation named "sbtest3". + Did not find any relation named "sbtest4". + Did not find any relation named "sbtest5". + Did not find any relation named "sbtest6". + Did not find any relation named "sbtest7". + Did not find any relation named "sbtest8". + 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'... + Did not find any relation named "sbtest1". + Did not find any relation named "sbtest2". + Did not find any relation named "sbtest3". + Did not find any relation named "sbtest4". + Did not find any relation named "sbtest5". + Did not find any relation named "sbtest6". + Did not find any relation named "sbtest7". + Did not find any relation named "sbtest8". + sysbench 1.0: multi-threaded system evaluation benchmark + + Creating table 'sbtest1'... + Inserting 10000 records into 'sbtest1' + Creating secondary indexes on 'sbtest1'... + Table "public.sbtest1" + Column | Type | Modifiers | Storage | Stats target | Description + --------+----------------+------------------------------------------------------+----------+--------------+------------- + id | integer | not null default nextval('sbtest1_id_seq'::regclass) | plain | | + k | integer | not null default 0 | plain | | + c | character(120) | not null default ''::bpchar | extended | | + pad | character(60) | not null default ''::bpchar | extended | | + Indexes: + "sbtest1_pkey" PRIMARY KEY, btree (id) + "k_1" btree (k) + + Did not find any relation named "sbtest2". + Did not find any relation named "sbtest3". + Did not find any relation named "sbtest4". + Did not find any relation named "sbtest5". + Did not find any relation named "sbtest6". + Did not find any relation named "sbtest7". + Did not find any relation named "sbtest8". + 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 1.0: multi-threaded system evaluation benchmark + + Dropping table 'sbtest1'... + Did not find any relation named "sbtest1". + Did not find any relation named "sbtest2". + Did not find any relation named "sbtest3". + Did not find any relation named "sbtest4". + Did not find any relation named "sbtest5". + Did not find any relation named "sbtest6". + Did not find any relation named "sbtest7". + Did not find any relation named "sbtest8". From 4dc366e950de6261180767a8fa6e4e42dfa1210e Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Fri, 9 Dec 2016 22:19:37 +0300 Subject: [PATCH 6/8] Add LuaJIT build/install directories to .gitignore. --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index fddcba6..b3f34ec 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,8 @@ GTAGS *.gcda *.gcno /tests/include/config.sh +third_party/luajit/bin/ +third_party/luajit/inc/ +third_party/luajit/lib/ +third_party/luajit/share/ +third_party/luajit/tmp/ From 482136beb515d44feee74c9165cdf0631b537a1e Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Mon, 12 Dec 2016 22:48:11 +0300 Subject: [PATCH 7/8] Lua implementation of the main event loop. For Lua scripts the main event loop is now implemented in Lua itself. This is a prerequisite for leveraging LuaJIT optimizations. --- .gitignore | 1 + configure.ac | 8 +- sysbench/CMakeLists.txt | 7 +- sysbench/Makefile.am | 11 +- sysbench/{scripting => lua}/Makefile.am | 13 +- .../internal/Makefile.am} | 18 +- sysbench/lua/internal/sysbench.lua | 59 ++++ sysbench/sb_logger.c | 17 +- sysbench/sb_logger.h | 28 +- sysbench/{scripting/script_lua.c => sb_lua.c} | 326 ++++++++++-------- sysbench/{scripting/script_lua.h => sb_lua.h} | 4 +- sysbench/scripting/sb_script.c | 39 --- sysbench/scripting/sb_script.h | 32 -- sysbench/sysbench.c | 240 +++++++------ sysbench/sysbench.h | 19 +- sysbench/tests/cpu/sb_cpu.c | 53 +-- sysbench/tests/fileio/sb_fileio.c | 69 ++-- sysbench/tests/memory/sb_memory.c | 52 +-- sysbench/tests/mutex/sb_mutex.c | 50 +-- sysbench/tests/threads/sb_threads.c | 53 +-- tests/t/test_fileio.t | 8 +- 21 files changed, 547 insertions(+), 560 deletions(-) rename sysbench/{scripting => lua}/Makefile.am (73%) rename sysbench/{scripting/CMakeLists.txt => lua/internal/Makefile.am} (75%) create mode 100644 sysbench/lua/internal/sysbench.lua rename sysbench/{scripting/script_lua.c => sb_lua.c} (79%) rename sysbench/{scripting/script_lua.h => sb_lua.h} (87%) delete mode 100644 sysbench/scripting/sb_script.c delete mode 100644 sysbench/scripting/sb_script.h diff --git a/.gitignore b/.gitignore index b3f34ec..89564a1 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,4 @@ third_party/luajit/inc/ third_party/luajit/lib/ third_party/luajit/share/ third_party/luajit/tmp/ +sysbench/lua/internal/sysbench.lua.h diff --git a/configure.ac b/configure.ac index 5168cb0..94ec855 100644 --- a/configure.ac +++ b/configure.ac @@ -31,6 +31,11 @@ m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) #LT_LIB_DLLOAD AC_PROG_LIBTOOL +AC_CHECK_PROG(sb_have_xxd, xxd, yes, no) +if test x"$sb_have_xxd" = xno; then + AC_MSG_ERROR("xxd is required to build sysbench (usually comes with the vim package)") +fi + AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) AC_MSG_CHECKING("C Compiler version") @@ -495,7 +500,8 @@ sysbench/tests/memory/Makefile sysbench/tests/threads/Makefile sysbench/tests/mutex/Makefile sysbench/tests/db/Makefile -sysbench/scripting/Makefile +sysbench/lua/Makefile +sysbench/lua/internal/Makefile tests/Makefile tests/include/config.sh ]) diff --git a/sysbench/CMakeLists.txt b/sysbench/CMakeLists.txt index 43a7af8..994139d 100644 --- a/sysbench/CMakeLists.txt +++ b/sysbench/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2008 MySQL AB -# Copyright (C) 2008-2011 Alexey Kopytov +# Copyright (C) 2008-2016 Alexey Kopytov # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -106,11 +106,6 @@ target_link_libraries (sysbench sbfileio) add_subdirectory(tests/mutex) target_link_libraries (sysbench sbmutex) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -add_subdirectory(scripting) -target_link_libraries(sysbench sbscript lua) - - add_subdirectory(tests/threads) target_link_libraries (sysbench sbthreads) diff --git a/sysbench/Makefile.am b/sysbench/Makefile.am index 29277d1..046a67c 100644 --- a/sysbench/Makefile.am +++ b/sysbench/Makefile.am @@ -1,5 +1,5 @@ # Copyright (C) 2004 MySQL AB -# Copyright (C) 2004-2014 Alexey Kopytov +# Copyright (C) 2004-2016 Alexey Kopytov # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,7 +15,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -SUBDIRS = drivers tests scripting . +SUBDIRS = drivers tests lua . + +AM_CPPFLAGS += -DDATA_PATH=\"$(pkgdatadir)\" bin_PROGRAMS = sysbench @@ -47,11 +49,12 @@ luajit_ldadd = $(LUAJIT_LIBS) sysbench_SOURCES = sysbench.c sysbench.h sb_timer.c sb_timer.h \ sb_options.c sb_options.h sb_logger.c sb_logger.h sb_list.h db_driver.h \ db_driver.c sb_percentile.c sb_percentile.h sb_rnd.c sb_rnd.h \ -sb_thread.c sb_thread.h sb_barrier.c sb_barrier.h sb_global.h +sb_thread.c sb_thread.h sb_barrier.c sb_barrier.h sb_global.h sb_lua.c \ +sb_lua.h lua/internal/sysbench.lua.h sysbench_LDADD = tests/fileio/libsbfileio.a tests/threads/libsbthreads.a \ tests/memory/libsbmemory.a tests/cpu/libsbcpu.a \ - tests/mutex/libsbmutex.a scripting/libsbscript.a \ + tests/mutex/libsbmutex.a \ $(mysql_ldadd) $(drizzle_ldadd) $(attachsql_ldadd) $(pgsql_ldadd) \ $(ora_ldadd) $(luajit_ldadd) diff --git a/sysbench/scripting/Makefile.am b/sysbench/lua/Makefile.am similarity index 73% rename from sysbench/scripting/Makefile.am rename to sysbench/lua/Makefile.am index 0c2862a..bf76623 100644 --- a/sysbench/scripting/Makefile.am +++ b/sysbench/lua/Makefile.am @@ -1,22 +1,17 @@ -# Copyright (C) 2006 MySQL AB -# Copyright (C) 2006-2016 Alexey Kopytov +# Copyright (C) 2016 Alexey Kopytov # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -AM_CPPFLAGS += -DDATA_PATH=\"$(pkgdatadir)\" - -noinst_LIBRARIES = libsbscript.a - -libsbscript_a_SOURCES = sb_script.c sb_script.h script_lua.c script_lua.h +SUBDIRS = internal diff --git a/sysbench/scripting/CMakeLists.txt b/sysbench/lua/internal/Makefile.am similarity index 75% rename from sysbench/scripting/CMakeLists.txt rename to sysbench/lua/internal/Makefile.am index 7126aa2..42e63ae 100644 --- a/sysbench/scripting/CMakeLists.txt +++ b/sysbench/lua/internal/Makefile.am @@ -1,21 +1,25 @@ -# Copyright (C) 2008 MySQL AB -# Copyright (C) 2008 Alexey Kopytov +# Copyright (C) 2016 Alexey Kopytov # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -include_directories(lua/src ..) -add_subdirectory(lua/src) -add_library(sbscript sb_script.c sb_script.h script_lua.c script_lua.h) +BUILT_SOURCES = sysbench.lua.h +CLEARFILES = sysbench.lua.h +EXTRA_DIST = sysbench.lua + +SUFFIXES = .lua .lua.h + +.lua.lua.h: + xxd -i $< $@ diff --git a/sysbench/lua/internal/sysbench.lua b/sysbench/lua/internal/sysbench.lua new file mode 100644 index 0000000..4775aa4 --- /dev/null +++ b/sysbench/lua/internal/sysbench.lua @@ -0,0 +1,59 @@ +-- Copyright (C) 2016 Alexey Kopytov + +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +-- ---------------------------------------------------------------------- +-- Compatibility aliases. These may be removed in later versions +-- ---------------------------------------------------------------------- + +sb_rand = sysbench.rand +sb_rand_uniq = sb_rand_uniq +sb_rnd = sysbench.rnd +sb_rand_str = sysbench.rand_str +sb_rand_uniform = sysbench.rand_uniform +sb_rand_gaussian = sysbench.rand_gaussian +sb_rand_special = sysbench.rand_special + +db_connect = sysbench.db.connect +db_disconnect = sysbench.db.disconnect + +db_query = sysbench.db.query + +db_bulk_insert_init = sysbench.db.bulk_insert_init +db_bulk_insert_next = sysbench.db.bulk_insert_next +db_bulk_insert_done = sysbench.db.bulk_insert_done + +db_prepare = sysbench.db.prepare +db_bind_param = sysbench.db.bind_param +db_bind_result = sysbench.db.bind_result +db_execute = sysbench.db.execute + +db_store_results = sysbench.db.store_results +db_free_results = sysbench.db.free_results + +DB_ERROR_NONE = sysbench.db.DB_ERROR_NONE +DB_ERROR_RESTART_TRANSACTION = sysbench.db.DB_ERROR_RESTART_TRANSACTION +DB_ERROR_FAILED = sysbench.db.DB_ERROR_FAILED + +-- ---------------------------------------------------------------------- +-- Main event loop. This is a Lua version of sysbench.c:thread_run() +-- ---------------------------------------------------------------------- +function thread_run() + while sysbench.more_events() do + sysbench.event_start() + event() + sysbench.event_stop() + end +end diff --git a/sysbench/sb_logger.c b/sysbench/sb_logger.c index 785d669..30d4747 100644 --- a/sysbench/sb_logger.c +++ b/sysbench/sb_logger.c @@ -50,6 +50,14 @@ /* per-thread timers for response time stats */ sb_timer_t *timers; +/* + Mutex protecting timers. + TODO: replace with an rwlock (and implement pthread rwlocks for Windows). +*/ +pthread_mutex_t timers_mutex; + +sb_percentile_t percentile; + /* Array of message handlers (one chain per message type) */ static sb_list_t handlers[LOG_MSG_TYPE_MAX]; @@ -57,8 +65,6 @@ static sb_list_t handlers[LOG_MSG_TYPE_MAX]; /* set after logger initialization */ static unsigned char initialized; -static sb_percentile_t percentile; - static pthread_mutex_t text_mutex; static unsigned int text_cnt; static char text_buf[TEXT_BUFFER_SIZE]; @@ -66,11 +72,6 @@ static char text_buf[TEXT_BUFFER_SIZE]; /* Temporary copy of timers */ static sb_timer_t *timers_copy; -/* - Mutex protecting timers. - TODO: replace with an rwlock (and implement pthread rwlocks for Windows). -*/ -static pthread_mutex_t timers_mutex; static int text_handler_init(void); static int text_handler_process(log_msg_t *msg); @@ -135,7 +136,7 @@ int log_register(void) log_add_handler(LOG_MSG_TYPE_TEXT, &text_handler); log_add_handler(LOG_MSG_TYPE_OPER, &oper_handler); - + return 0; } diff --git a/sysbench/sb_logger.h b/sysbench/sb_logger.h index 2d0644b..b02d314 100644 --- a/sysbench/sb_logger.h +++ b/sysbench/sb_logger.h @@ -1,5 +1,5 @@ /* Copyright (C) 2004 MySQL AB - Copyright (C) 2004-2011 Alexey Kopytov + Copyright (C) 2004-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,32 +23,19 @@ # include "config.h" #endif +#ifdef HAVE_PTHREAD_H +# include +#endif + #include "sb_global.h" #include "sb_options.h" #include "sb_timer.h" +#include "sb_percentile.h" /* Text message flags (used in the 'flags' field of log_text_msg_t) */ #define LOG_MSG_TEXT_ALLOW_DUPLICATES 1 -/* Macros to log per-request execution statistics */ - -#define LOG_EVENT_START(msg, thread_id) \ - do \ - { \ - ((log_msg_oper_t *)(msg).data)->thread_id = thread_id; \ - ((log_msg_oper_t *)(msg).data)->action = LOG_MSG_OPER_START; \ - log_msg(&(msg)); \ - } while (0); - -#define LOG_EVENT_STOP(msg, thread_id) \ - do \ - { \ - ((log_msg_oper_t *)(msg).data)->thread_id = thread_id; \ - ((log_msg_oper_t *)(msg).data)->action = LOG_MSG_OPER_STOP; \ - log_msg(&(msg)); \ - } while (0); - /* Message types definition */ typedef enum { @@ -122,6 +109,9 @@ typedef struct { /* per-thread timers for response time stats */ extern sb_timer_t *timers; +extern pthread_mutex_t timers_mutex; + +extern sb_percentile_t percentile; /* Register logger */ diff --git a/sysbench/scripting/script_lua.c b/sysbench/sb_lua.c similarity index 79% rename from sysbench/scripting/script_lua.c rename to sysbench/sb_lua.c index 5590d7f..88be839 100644 --- a/sysbench/scripting/script_lua.c +++ b/sysbench/sb_lua.c @@ -1,5 +1,5 @@ /* Copyright (C) 2006 MySQL AB - Copyright (C) 2006-2015 Alexey Kopytov + Copyright (C) 2006-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,23 +20,25 @@ # include "config.h" #endif -#include "script_lua.h" +#include "sb_lua.h" #include "lua.h" #include "lualib.h" #include "lauxlib.h" -#include "sb_script.h" #include "db_driver.h" #include "sb_rnd.h" +#include "sb_thread.h" -#include +/* Auto-generated headers */ +#include "lua/internal/sysbench.lua.h" #define EVENT_FUNC "event" #define PREPARE_FUNC "prepare" #define CLEANUP_FUNC "cleanup" +#define HELP_FUNC "help" #define THREAD_INIT_FUNC "thread_init" #define THREAD_DONE_FUNC "thread_done" -#define HELP_FUNC "help" +#define THREAD_RUN_FUNC "thread_run" /* Macros to call Lua functions */ #define CALL_ERROR(L, name) \ @@ -55,7 +57,7 @@ /* Interpreter context */ typedef struct { - int thread_id; /* SysBench thread ID */ + int thread_id; /* sysbench thread id */ db_conn_t *con; /* Database connection */ } sb_lua_ctxt_t; @@ -89,27 +91,24 @@ static lua_State **states; /* Event counter */ static unsigned int nevents; +static sb_test_t sbtest; + /* Lua test operations */ static int sb_lua_init(void); static int sb_lua_done(void); -static sb_request_t sb_lua_get_request(int thread_id); -static int sb_lua_op_execute_request(sb_request_t *, int); +static sb_event_t sb_lua_next_event(int); +static int sb_lua_op_execute_event(sb_event_t *, int); static int sb_lua_op_thread_init(int); +static int sb_lua_op_thread_run(int); static int sb_lua_op_thread_done(int); static void sb_lua_op_print_stats(sb_stat_t type); static sb_operations_t lua_ops = { - &sb_lua_init, - NULL, - NULL, - NULL, - &sb_lua_get_request, - &sb_lua_op_execute_request, - NULL, - NULL, - NULL, - &sb_lua_done + .init = sb_lua_init, + .next_event = &sb_lua_next_event, + .execute_event = sb_lua_op_execute_event, + .done = sb_lua_done }; /* Main (global) interpreter state */ @@ -156,6 +155,9 @@ static int sb_lua_rand_gaussian(lua_State *); static int sb_lua_rand_special(lua_State *); static int sb_lua_rnd(lua_State *); static int sb_lua_rand_str(lua_State *); +static int sb_lua_more_events(lua_State *); +static int sb_lua_event_start(lua_State *); +static int sb_lua_event_stop(lua_State *); /* Get a per-state interpreter context */ static sb_lua_ctxt_t *sb_lua_get_context(lua_State *); @@ -167,7 +169,7 @@ unsigned int sb_lua_table_size(lua_State *, int); /* Load a specified Lua script */ -int script_load_lua(const char *testname, sb_test_t *test) +sb_test_t *sb_load_lua(const char *testname) { unsigned int i; @@ -181,30 +183,34 @@ int script_load_lua(const char *testname, sb_test_t *test) /* Test commands */ lua_getglobal(gstate, PREPARE_FUNC); if (!lua_isnil(gstate, -1)) - test->cmds.prepare = &sb_lua_cmd_prepare; + sbtest.cmds.prepare = &sb_lua_cmd_prepare; lua_pop(gstate, 1); lua_getglobal(gstate, CLEANUP_FUNC); if (!lua_isnil(gstate, -1)) - test->cmds.cleanup = &sb_lua_cmd_cleanup; + sbtest.cmds.cleanup = &sb_lua_cmd_cleanup; lua_getglobal(gstate, HELP_FUNC); if (!lua_isnil(gstate, -1) && lua_isfunction(gstate, -1)) - test->cmds.help = &sb_lua_cmd_help; + sbtest.cmds.help = &sb_lua_cmd_help; /* Test operations */ - test->ops = lua_ops; + sbtest.ops = lua_ops; lua_getglobal(gstate, THREAD_INIT_FUNC); if (!lua_isnil(gstate, -1)) - test->ops.thread_init = &sb_lua_op_thread_init; + sbtest.ops.thread_init = &sb_lua_op_thread_init; lua_getglobal(gstate, THREAD_DONE_FUNC); if (!lua_isnil(gstate, -1)) - test->ops.thread_done = &sb_lua_op_thread_done; + sbtest.ops.thread_done = &sb_lua_op_thread_done; + + lua_getglobal(gstate, THREAD_RUN_FUNC); + if (!lua_isnil(gstate, -1)) + sbtest.ops.thread_run = &sb_lua_op_thread_run; - test->ops.print_stats = &sb_lua_op_print_stats; + sbtest.ops.print_stats = &sb_lua_op_print_stats; /* Initialize per-thread interpreters */ states = (lua_State **)calloc(sb_globals.num_threads, sizeof(lua_State *)); @@ -217,7 +223,7 @@ int script_load_lua(const char *testname, sb_test_t *test) goto error; } - return 0; + return &sbtest; error: @@ -229,7 +235,7 @@ int script_load_lua(const char *testname, sb_test_t *test) free(states); } - return 1; + return NULL; } /* Initialize Lua script */ @@ -239,9 +245,9 @@ int sb_lua_init(void) return 0; } -sb_request_t sb_lua_get_request(int thread_id) +sb_event_t sb_lua_next_event(int thread_id) { - sb_request_t req; + sb_event_t req; (void) thread_id; /* unused */ @@ -263,30 +269,21 @@ sb_request_t sb_lua_get_request(int thread_id) return req; } -int sb_lua_op_execute_request(sb_request_t *sb_req, int thread_id) +int sb_lua_op_execute_event(sb_event_t *sb_req, int thread_id) { - log_msg_t msg; - log_msg_oper_t op_msg; - unsigned int restart; + unsigned int restart; lua_State *L = states[thread_id]; (void)sb_req; /* unused */ - - /* Prepare log message */ - msg.type = LOG_MSG_TYPE_OPER; - msg.data = &op_msg; - - LOG_EVENT_START(msg, thread_id); + (void)thread_id; /* unused */ do { restart = 0; lua_getglobal(L, EVENT_FUNC); - - lua_pushnumber(L, thread_id); - if (lua_pcall(L, 1, 1, 0)) + if (lua_pcall(L, 0, 1, 0)) { if (lua_gettop(L) && lua_isnumber(L, -1) && lua_tonumber(L, -1) == SB_DB_ERROR_RESTART_TRANSACTION) @@ -305,8 +302,6 @@ int sb_lua_op_execute_request(sb_request_t *sb_req, int thread_id) } lua_pop(L, 1); } while (restart); - - LOG_EVENT_STOP(msg, thread_id); if (db_driver != NULL) sb_percentile_update(&local_percentile, sb_timer_value(&timers[thread_id])); @@ -316,33 +311,49 @@ int sb_lua_op_execute_request(sb_request_t *sb_req, int thread_id) int sb_lua_op_thread_init(int thread_id) { - sb_lua_ctxt_t *ctxt; + sb_lua_ctxt_t *ctxt; + lua_State * const L = states[thread_id]; - ctxt = sb_lua_get_context(states[thread_id]); + ctxt = sb_lua_get_context(L); if (ctxt->con == NULL) - sb_lua_db_connect(states[thread_id]); + sb_lua_db_connect(L); - lua_getglobal(states[thread_id], THREAD_INIT_FUNC); - lua_pushnumber(states[thread_id], (double)thread_id); - - if (lua_pcall(states[thread_id], 1, 1, 0)) + lua_getglobal(L, THREAD_INIT_FUNC); + + if (lua_pcall(L, 0, 1, 0)) { - CALL_ERROR(states[thread_id], THREAD_INIT_FUNC); + CALL_ERROR(L, THREAD_INIT_FUNC); return 1; } - + + return 0; +} + +int sb_lua_op_thread_run(int thread_id) +{ + lua_State * const L = states[thread_id]; + + lua_getglobal(L, THREAD_RUN_FUNC); + + if (lua_pcall(L, 0, 1, 0)) + { + CALL_ERROR(L, THREAD_RUN_FUNC); + return 1; + } + return 0; } int sb_lua_op_thread_done(int thread_id) { - lua_getglobal(states[thread_id], THREAD_DONE_FUNC); - lua_pushnumber(states[thread_id], (double)thread_id); + lua_State * const L = states[thread_id]; - if (lua_pcall(states[thread_id], 1, 1, 0)) + lua_getglobal(L, THREAD_DONE_FUNC); + + if (lua_pcall(L, 0, 1, 0)) { - CALL_ERROR(states[thread_id], THREAD_DONE_FUNC); + CALL_ERROR(L, THREAD_DONE_FUNC); return 1; } @@ -372,15 +383,15 @@ int sb_lua_done(void) lua_State *sb_lua_new_state(const char *scriptname, int thread_id) { - lua_State *state; + lua_State *L; sb_lua_ctxt_t *ctxt; sb_list_item_t *pos; option_t *opt; char *tmp; - state = luaL_newstate(); + L = luaL_newstate(); - luaL_openlibs(state); + luaL_openlibs(L); /* Export all global options */ pos = sb_options_enum_start(); @@ -389,112 +400,113 @@ lua_State *sb_lua_new_state(const char *scriptname, int thread_id) switch (opt->type) { case SB_ARG_TYPE_FLAG: - lua_pushboolean(state, sb_opt_to_flag(opt)); + lua_pushboolean(L, sb_opt_to_flag(opt)); break; case SB_ARG_TYPE_INT: - lua_pushnumber(state, sb_opt_to_int(opt)); + lua_pushnumber(L, sb_opt_to_int(opt)); break; case SB_ARG_TYPE_FLOAT: - lua_pushnumber(state, sb_opt_to_float(opt)); + lua_pushnumber(L, sb_opt_to_float(opt)); break; case SB_ARG_TYPE_SIZE: - lua_pushnumber(state, sb_opt_to_size(opt)); + lua_pushnumber(L, sb_opt_to_size(opt)); break; case SB_ARG_TYPE_STRING: tmp = sb_opt_to_string(opt); - lua_pushstring(state, tmp ? tmp : ""); + lua_pushstring(L, tmp ? tmp : ""); break; case SB_ARG_TYPE_LIST: /*FIXME: should be exported as tables */ - lua_pushnil(state); + lua_pushnil(L); break; case SB_ARG_TYPE_FILE: /* FIXME: no need to export anything */ - lua_pushnil(state); + lua_pushnil(L); break; default: log_text(LOG_WARNING, "Global option '%s' will not be exported, because" " the type is unknown", opt->name); - lua_pushnil(state); + lua_pushnil(L); break; } - lua_setglobal(state, opt->name); + lua_setglobal(L, opt->name); } - - /* Export functions */ - lua_pushcfunction(state, sb_lua_rand); - lua_setglobal(state, "sb_rand"); - lua_pushcfunction(state, sb_lua_rand_uniq); - lua_setglobal(state, "sb_rand_uniq"); +#define SB_LUA_VAR(luaname, cname) \ + lua_pushstring(L, luaname); \ + lua_pushnumber(L, cname); \ + lua_settable(L, -3) +#define SB_LUA_FUNC(luaname, cname) \ + lua_pushstring(L, luaname); \ + lua_pushcfunction(L, cname); \ + lua_settable(L, -3) - lua_pushcfunction(state, sb_lua_rnd); - lua_setglobal(state, "sb_rnd"); + /* Export variables into per-L 'sysbench' table */ - lua_pushcfunction(state, sb_lua_rand_str); - lua_setglobal(state, "sb_rand_str"); + lua_newtable(L); - lua_pushcfunction(state, sb_lua_rand_uniform); - lua_setglobal(state, "sb_rand_uniform"); + /* sysbench.tid */ + SB_LUA_VAR("tid", thread_id); - lua_pushcfunction(state, sb_lua_rand_gaussian); - lua_setglobal(state, "sb_rand_gaussian"); + /* Export functions into per-L 'sysbench' table */ - lua_pushcfunction(state, sb_lua_rand_special); - lua_setglobal(state, "sb_rand_special"); + SB_LUA_FUNC("more_events", sb_lua_more_events); + SB_LUA_FUNC("event_start", sb_lua_event_start); + SB_LUA_FUNC("event_stop", sb_lua_event_stop); - lua_pushcfunction(state, sb_lua_db_connect); - lua_setglobal(state, "db_connect"); - - lua_pushcfunction(state, sb_lua_db_disconnect); - lua_setglobal(state, "db_disconnect"); + SB_LUA_FUNC("rand", sb_lua_rand); + SB_LUA_FUNC("rand_uniq", sb_lua_rand_uniq); + SB_LUA_FUNC("rnd", sb_lua_rnd); + SB_LUA_FUNC("rand_str", sb_lua_rand_str); + SB_LUA_FUNC("rand_uniform", sb_lua_rand_uniform); + SB_LUA_FUNC("rand_gaussian", sb_lua_rand_gaussian); + SB_LUA_FUNC("rand_special", sb_lua_rand_special); - lua_pushcfunction(state, sb_lua_db_query); - lua_setglobal(state, "db_query"); - - lua_pushcfunction(state, sb_lua_db_bulk_insert_init); - lua_setglobal(state, "db_bulk_insert_init"); - - lua_pushcfunction(state, sb_lua_db_bulk_insert_next); - lua_setglobal(state, "db_bulk_insert_next"); - - lua_pushcfunction(state, sb_lua_db_bulk_insert_done); - lua_setglobal(state, "db_bulk_insert_done"); + /* Export functions into per-L 'sysbench.db' table */ - lua_pushcfunction(state, sb_lua_db_prepare); - lua_setglobal(state, "db_prepare"); + lua_pushstring(L, "db"); + lua_newtable(L); - lua_pushcfunction(state, sb_lua_db_bind_param); - lua_setglobal(state, "db_bind_param"); + SB_LUA_FUNC("connect", sb_lua_db_connect); + SB_LUA_FUNC("disconnect", sb_lua_db_disconnect); + SB_LUA_FUNC("query", sb_lua_db_query); + SB_LUA_FUNC("bulk_insert_init", sb_lua_db_bulk_insert_init); + SB_LUA_FUNC("bulk_insert_next", sb_lua_db_bulk_insert_next); + SB_LUA_FUNC("bulk_insert_done", sb_lua_db_bulk_insert_done); + SB_LUA_FUNC("prepare", sb_lua_db_prepare); + SB_LUA_FUNC("bind_param", sb_lua_db_bind_param); + SB_LUA_FUNC("bind_result", sb_lua_db_bind_result); + SB_LUA_FUNC("execute", sb_lua_db_execute); + SB_LUA_FUNC("close", sb_lua_db_close); + SB_LUA_FUNC("store_results", sb_lua_db_store_results); + SB_LUA_FUNC("free_results", sb_lua_db_free_results); - lua_pushcfunction(state, sb_lua_db_bind_result); - lua_setglobal(state, "db_bind_result"); + SB_LUA_VAR("DB_ERROR_NONE", SB_DB_ERROR_NONE); + SB_LUA_VAR("DB_ERROR_RESTART_TRANSACTION", SB_DB_ERROR_RESTART_TRANSACTION); + SB_LUA_VAR("DB_ERROR_FAILED", SB_DB_ERROR_FAILED); - lua_pushcfunction(state, sb_lua_db_execute); - lua_setglobal(state, "db_execute"); - - lua_pushcfunction(state, sb_lua_db_close); - lua_setglobal(state, "db_close"); +#undef SB_LUA_VAR +#undef SB_LUA_FUNC - lua_pushcfunction(state, sb_lua_db_store_results); - lua_setglobal(state, "db_store_results"); + lua_settable(L, -3); /* sysbench.db */ - lua_pushcfunction(state, sb_lua_db_free_results); - lua_setglobal(state, "db_free_results"); - - lua_pushnumber(state, SB_DB_ERROR_NONE); - lua_setglobal(state, "DB_ERROR_NONE"); - lua_pushnumber(state, SB_DB_ERROR_RESTART_TRANSACTION); - lua_setglobal(state, "DB_ERROR_RESTART_TRANSACTION"); - lua_pushnumber(state, SB_DB_ERROR_FAILED); - lua_setglobal(state, "DB_ERROR_FAILED"); + lua_setglobal(L, "sysbench"); - luaL_newmetatable(state, "sysbench.stmt"); + luaL_newmetatable(L, "sysbench.stmt"); + luaL_newmetatable(L, "sysbench.rs"); - luaL_newmetatable(state, "sysbench.rs"); + /* Pre-load internal modules */ + if (luaL_loadbuffer(L, (const char *) sysbench_lua, sysbench_lua_len, + "sysbench.lua")) + { + log_text(LOG_FATAL, "failed to load internal module sysbench.lua: %s", + lua_tostring(L, -1)); + } + lua_pushstring(L, "sysbench"); + lua_call(L, 1, 0); - if (luaL_loadfile(state, scriptname)) + if (luaL_loadfile(L, scriptname)) { /* first location failed - look in DATA_PATH */ char p[PATH_MAX + 1]; @@ -506,27 +518,29 @@ lua_State *sb_lua_new_state(const char *scriptname, int thread_id) strncat(p, ".lua", sizeof(p)-strlen(p)-1); } - if (luaL_loadfile(state, p)) + if (luaL_loadfile(L, p)) { - lua_error(state); + lua_error(L); return NULL; } } - if (lua_pcall(state, 0, 0, 0)) + if (lua_pcall(L, 0, 0, 0)) { - lua_error(state); + lua_error(L); return NULL; } - /* Create new state context */ + /* Create new L context */ ctxt = (sb_lua_ctxt_t *)calloc(1, sizeof(sb_lua_ctxt_t)); if (ctxt == NULL) return NULL; + ctxt->thread_id = thread_id; - sb_lua_set_context(state, ctxt); + + sb_lua_set_context(L, ctxt); - return state; + return L; } /* Close interpreter state */ @@ -613,8 +627,7 @@ int sb_lua_db_connect(lua_State *L) ctxt->con = db_connect(db_driver); if (ctxt->con == NULL) luaL_error(L, "Failed to connect to the database"); - db_set_thread(ctxt->con, ctxt->thread_id); - + return 0; } @@ -1173,3 +1186,44 @@ unsigned int sb_lua_table_size(lua_State *L, int index) return i; } + +/* Check if there are more events to execute */ + +int sb_lua_more_events(lua_State *L) +{ + sb_event_t e; + sb_lua_ctxt_t *ctxt; + + ctxt = sb_lua_get_context(L); + + e = sb_next_event(&sbtest, ctxt->thread_id); + lua_pushboolean(L, e.type == SB_REQ_TYPE_SCRIPT); + + return 1; +} + +/* Exported wrapper for sb_event_start() */ + +int sb_lua_event_start(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + + ctxt = sb_lua_get_context(L); + + sb_event_start(ctxt->thread_id); + + return 0; +} + +/* Exported wrapper for sb_event_stop() */ + +int sb_lua_event_stop(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + + ctxt = sb_lua_get_context(L); + + sb_event_stop(ctxt->thread_id); + + return 0; +} diff --git a/sysbench/scripting/script_lua.h b/sysbench/sb_lua.h similarity index 87% rename from sysbench/scripting/script_lua.h rename to sysbench/sb_lua.h index e35c1ed..cffcf2b 100644 --- a/sysbench/scripting/script_lua.h +++ b/sysbench/sb_lua.h @@ -1,5 +1,5 @@ /* Copyright (C) 2006 MySQL AB - Copyright (C) 2006 Alexey Kopytov + Copyright (C) 2006-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,4 +24,4 @@ /* Load a specified Lua script */ -int script_load_lua(const char *testname, sb_test_t *test); +sb_test_t *sb_load_lua(const char *testname); diff --git a/sysbench/scripting/sb_script.c b/sysbench/scripting/sb_script.c deleted file mode 100644 index face52c..0000000 --- a/sysbench/scripting/sb_script.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2006 MySQL AB - Copyright (C) 2006 Alexey Kopytov - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sb_script.h" - -#include "script_lua.h" - -static sb_test_t test; - -/* Initialize interpreter with a given script name */ - -sb_test_t *script_load(const char *testname) -{ - test.sname = strdup(testname); - - if (!script_load_lua(testname, &test)) - return &test; - - return NULL; -} diff --git a/sysbench/scripting/sb_script.h b/sysbench/scripting/sb_script.h deleted file mode 100644 index 75b9c5b..0000000 --- a/sysbench/scripting/sb_script.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2006 MySQL AB - Copyright (C) 2006 Alexey Kopytov - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef SB_SCRIPT_H -#define SB_SCRIPT_H - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sysbench.h" - -/* Initialize interpreter with a given script name */ - -sb_test_t *script_load(const char *testname); - -#endif /* SB_SCRIPT_H */ diff --git a/sysbench/sysbench.c b/sysbench/sysbench.c index 6ee56b4..e56d97f 100644 --- a/sysbench/sysbench.c +++ b/sysbench/sysbench.c @@ -68,7 +68,7 @@ #include "sysbench.h" #include "sb_options.h" -#include "scripting/sb_script.h" +#include "sb_lua.h" #include "db_driver.h" #include "sb_rnd.h" #include "sb_thread.h" @@ -223,44 +223,6 @@ static void sigalrm_forced_shutdown_handler(int sig) } #endif -/* Main request provider function */ - - -static sb_request_t get_request(sb_test_t *test, int thread_id) -{ - sb_request_t r; - (void)thread_id; /* unused */ - - if (test->ops.get_request != NULL) - r = test->ops.get_request(thread_id); - else - { - log_text(LOG_ALERT, "Unsupported mode! Creating NULL request."); - r.type = SB_REQ_TYPE_NULL; - } - - return r; -} - - -/* Main request execution function */ - - -static int execute_request(sb_test_t *test, sb_request_t *r,int thread_id) -{ - unsigned int rc; - - if (test->ops.execute_request != NULL) - rc = test->ops.execute_request(r, thread_id); - else - { - log_text(LOG_FATAL, "Unknown request. Aborting"); - rc = 1; - } - - return rc; -} - static int register_tests(void) { @@ -470,19 +432,138 @@ void print_run_mode(sb_test_t *test) test->ops.print_mode(); } +/* + Get the next event, or return an 'empty' event with type = SB_REQ_TYPE_NULL, + if there are no more events to execute. +*/ -/* Main worker test thread */ +sb_event_t sb_next_event(sb_test_t *test, int thread_id) +{ + sb_event_t event; + sb_list_item_t *pos; + event_queue_elem_t *elem; + unsigned long long queue_start_time = 0; + + event.type = SB_REQ_TYPE_NULL; + + if (sb_globals.error) + return event; + + /* Check if we have a time limit */ + if (sb_globals.max_time != 0 && + sb_timer_value(&sb_globals.exec_timer) >= SEC2NS(sb_globals.max_time)) + { + log_text(LOG_INFO, "Time limit exceeded, exiting..."); + return event; + } + + /* If we are in tx_rate mode, we take events from queue */ + if (sb_globals.tx_rate > 0) + { + if (queue_is_full) + { + log_text(LOG_FATAL, "Event queue is full."); + return event; + } + pthread_mutex_lock(&event_queue_mutex); + while(!sb_globals.event_queue_length) + pthread_cond_wait(&event_queue_cv, &event_queue_mutex); + + SB_LIST_ONCE(pos, &event_queue) + { + elem = SB_LIST_ENTRY(pos, event_queue_elem_t, listitem); + queue_start_time = elem->event_time;; + + SB_LIST_DELETE(pos); + + sb_globals.event_queue_length--; + } + + sb_globals.concurrency++; + + pthread_mutex_unlock(&event_queue_mutex); + + timers[thread_id].queue_time = sb_timer_value(&sb_globals.exec_timer) - + queue_start_time; + + } + + event = test->ops.next_event(thread_id); + + return event; +} + + +void sb_event_start(int thread_id) +{ + sb_timer_t *timer = &timers[thread_id]; + + if (sb_globals.n_checkpoints > 0) + pthread_mutex_lock(&timers_mutex); + + sb_timer_start(timer); + + if (sb_globals.n_checkpoints > 0) + pthread_mutex_unlock(&timers_mutex); +} + + +void sb_event_stop(int thread_id) +{ + sb_timer_t *timer = &timers[thread_id]; + long long value; + + if (sb_globals.n_checkpoints > 0) + pthread_mutex_lock(&timers_mutex); + + sb_timer_stop(timer); + + value = sb_timer_value(timer); + + if (sb_globals.n_checkpoints > 0) + pthread_mutex_unlock(&timers_mutex); + + sb_percentile_update(&percentile, value); +} + + +/* Main event loop -- the default thread_run implementation */ + + +static void thread_run(sb_test_t *test, int thread_id) +{ + sb_event_t event; + int rc; + + while ((event = sb_next_event(test, thread_id)).type != SB_REQ_TYPE_NULL) + { + sb_event_start(thread_id); + + rc = test->ops.execute_event(&event, thread_id); + + sb_event_stop(thread_id); + + if (sb_globals.tx_rate > 0) + { + pthread_mutex_lock(&event_queue_mutex); + sb_globals.concurrency--; + pthread_mutex_unlock(&event_queue_mutex); + } + + if (rc != 0) + break; + } +} + + +/* Main worker thread */ static void *worker_thread(void *arg) { - sb_request_t request; sb_thread_ctxt_t *ctxt; sb_test_t *test; - unsigned int thread_id; - unsigned long long queue_start_time = 0; - sb_list_item_t *pos; - event_queue_elem_t *event; + unsigned int thread_id; ctxt = (sb_thread_ctxt_t *)arg; test = ctxt->test; @@ -508,65 +589,16 @@ static void *worker_thread(void *arg) if (sb_barrier_wait(&thread_start_barrier) < 0) return NULL; - do + if (test->ops.thread_run != NULL) { - - /* If we are in tx_rate mode, we take events from queue */ - if (sb_globals.tx_rate > 0) - { - if (queue_is_full) - { - log_text(LOG_FATAL, "Event queue is full."); - break; - } - pthread_mutex_lock(&event_queue_mutex); - while(!sb_globals.event_queue_length) - pthread_cond_wait(&event_queue_cv, &event_queue_mutex); - - SB_LIST_ONCE(pos, &event_queue) - { - event = SB_LIST_ENTRY(pos, event_queue_elem_t, listitem); - queue_start_time = event->event_time;; - - SB_LIST_DELETE(pos); - - sb_globals.event_queue_length--; - } - - sb_globals.concurrency++; - - pthread_mutex_unlock(&event_queue_mutex); - - timers[thread_id].queue_time = sb_timer_value(&sb_globals.exec_timer) - - queue_start_time; - - } - - request = get_request(test, thread_id); - - /* check if we shall execute it */ - if (request.type != SB_REQ_TYPE_NULL) - { - if (execute_request(test, &request, thread_id)) - break; /* break if error returned (terminates only one thread) */ - } - - if (sb_globals.tx_rate > 0) - { - pthread_mutex_lock(&event_queue_mutex); - sb_globals.concurrency--; - pthread_mutex_unlock(&event_queue_mutex); - } - - /* Check if we have a time limit */ - if (sb_globals.max_time != 0 && - sb_timer_value(&sb_globals.exec_timer) >= SEC2NS(sb_globals.max_time)) - { - log_text(LOG_INFO, "Time limit exceeded, exiting..."); - break; - } - - } while ((request.type != SB_REQ_TYPE_NULL) && (!sb_globals.error) ); + /* Use benchmark-provided thread_run implementation */ + test->ops.thread_run(thread_id); + } + else + { + /* Use default thread_run implementation */ + thread_run(test, thread_id); + } if (test->ops.thread_done != NULL) test->ops.thread_done(thread_id); @@ -1208,7 +1240,7 @@ int main(int argc, char *argv[]) /* Check if the testname is a script filename */ if (test == NULL) - test = script_load(testname); + test = sb_load_lua(testname); } /* 'help' command */ diff --git a/sysbench/sysbench.h b/sysbench/sysbench.h index 2ba5f96..3699d15 100644 --- a/sysbench/sysbench.h +++ b/sysbench/sysbench.h @@ -23,6 +23,7 @@ # include # include # include +# include #endif #ifdef HAVE_UNISTD_H # include @@ -73,7 +74,7 @@ typedef enum SB_REQ_TYPE_THREADS, SB_REQ_TYPE_MUTEX, SB_REQ_TYPE_SCRIPT -} sb_request_type_t; +} sb_event_type_t; /* Request structure definition */ @@ -92,7 +93,7 @@ typedef struct sb_threads_request_t threads_request; sb_mutex_request_t mutex_request; } u; -} sb_request_t; +} sb_event_t; typedef enum { @@ -113,9 +114,10 @@ typedef int sb_cmd_cleanup(void); typedef int sb_op_init(void); typedef int sb_op_prepare(void); typedef int sb_op_thread_init(int); +typedef int sb_op_thread_run(int); typedef void sb_op_print_mode(void); -typedef sb_request_t sb_op_get_request(int); -typedef int sb_op_execute_request(sb_request_t *, int); +typedef sb_event_t sb_op_next_event(int); +typedef int sb_op_execute_event(sb_event_t *, int); typedef void sb_op_print_stats(sb_stat_t); typedef int sb_op_thread_done(int); typedef int sb_op_cleanup(void); @@ -141,9 +143,10 @@ typedef struct sb_op_thread_init *thread_init; /* thread initialization (called when each thread starts) */ sb_op_print_mode *print_mode; /* print mode function */ - sb_op_get_request *get_request; /* request generation function */ - sb_op_execute_request *execute_request; /* request execution function */ + sb_op_next_event *next_event; /* event generation function */ + sb_op_execute_event *execute_event; /* event execution function */ sb_op_print_stats *print_stats; /* stats generation function */ + sb_op_thread_run *thread_run; /* main thread loop */ sb_op_thread_done *thread_done; /* thread finalize function */ sb_op_cleanup *cleanup; /* called after exit from thread, but before timers stop */ @@ -210,6 +213,10 @@ typedef struct extern sb_globals_t sb_globals; extern pthread_mutex_t event_queue_mutex; +sb_event_t sb_next_event(sb_test_t *test, int thread_id); +void sb_event_start(int thread_id); +void sb_event_stop(int thread_id); + /* Random number generators */ int sb_rand(int, int); int sb_rand_uniform(int, int); diff --git a/sysbench/tests/cpu/sb_cpu.c b/sysbench/tests/cpu/sb_cpu.c index b2e665e..9c2d479 100644 --- a/sysbench/tests/cpu/sb_cpu.c +++ b/sysbench/tests/cpu/sb_cpu.c @@ -1,5 +1,5 @@ /* Copyright (C) 2004 MySQL AB - Copyright (C) 2004-2015 Alexey Kopytov + Copyright (C) 2004-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,31 +39,22 @@ static sb_arg_t cpu_args[] = /* CPU test operations */ static int cpu_init(void); static void cpu_print_mode(void); -static sb_request_t cpu_get_request(int thread_id); -static int cpu_execute_request(sb_request_t *, int); +static sb_event_t cpu_next_event(int thread_id); +static int cpu_execute_event(sb_event_t *, int); static int cpu_done(void); static sb_test_t cpu_test = { -"cpu", - "CPU performance test", - { - cpu_init, - NULL, - NULL, - cpu_print_mode, - cpu_get_request, - cpu_execute_request, - NULL, - NULL, - NULL, - cpu_done + .sname = "cpu", + .lname = "CPU performance test", + .ops = { + .init = cpu_init, + .print_mode = cpu_print_mode, + .next_event = cpu_next_event, + .execute_event = cpu_execute_event, + .done = cpu_done }, - { - NULL,NULL,NULL,NULL - }, - cpu_args, - {NULL, NULL} + .args = cpu_args }; /* Upper limit for primes */ @@ -94,9 +85,9 @@ int cpu_init(void) } -sb_request_t cpu_get_request(int thread_id) +sb_event_t cpu_next_event(int thread_id) { - sb_request_t req; + sb_event_t req; (void) thread_id; /* unused */ @@ -118,25 +109,19 @@ sb_request_t cpu_get_request(int thread_id) return req; } -int cpu_execute_request(sb_request_t *r, int thread_id) +int cpu_execute_event(sb_event_t *r, int thread_id) { unsigned long long c; unsigned long long l; double t; unsigned long long n=0; - log_msg_t msg; - log_msg_oper_t op_msg; - + + (void)thread_id; /* unused */ (void)r; /* unused */ - /* Prepare log message */ - msg.type = LOG_MSG_TYPE_OPER; - msg.data = &op_msg; - /* So far we're using very simple test prime number tests in 64bit */ - LOG_EVENT_START(msg, thread_id); - for(c=3; c < max_prime; c++) + for(c=3; c < max_prime; c++) { t = sqrt((double)c); for(l = 2; l <= t; l++) @@ -146,8 +131,6 @@ int cpu_execute_request(sb_request_t *r, int thread_id) n++; } - LOG_EVENT_STOP(msg, thread_id); - return 0; } diff --git a/sysbench/tests/fileio/sb_fileio.c b/sysbench/tests/fileio/sb_fileio.c index 0946081..560bb22 100644 --- a/sysbench/tests/fileio/sb_fileio.c +++ b/sysbench/tests/fileio/sb_fileio.c @@ -1,5 +1,5 @@ /* Copyright (C) 2004 MySQL AB - Copyright (C) 2004-2015 Alexey Kopytov + Copyright (C) 2004-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -237,8 +237,8 @@ static int file_cmd_cleanup(void); static int file_init(void); static void file_print_mode(void); static int file_prepare(void); -static sb_request_t file_get_request(int thread_id); -static int file_execute_request(sb_request_t *, int); +static sb_event_t file_next_event(int thread_id); +static int file_execute_event(sb_event_t *, int); #ifdef HAVE_LIBAIO static int file_thread_done(int); #endif @@ -247,32 +247,27 @@ static void file_print_stats(sb_stat_t); static sb_test_t fileio_test = { - "fileio", - "File I/O test", - { - file_init, - file_prepare, - NULL, - file_print_mode, - file_get_request, - file_execute_request, - file_print_stats, + .sname = "fileio", + .lname = "File I/O test", + .ops = { + .init = file_init, + .prepare = file_prepare, + .print_mode = file_print_mode, + .next_event = file_next_event, + .execute_event = file_execute_event, + .print_stats = file_print_stats, #ifdef HAVE_LIBAIO - file_thread_done, + .thread_done = file_thread_done, #else - NULL, + .thread_done = NULL, #endif - NULL, - file_done + .done = file_done }, - { - NULL, - file_cmd_prepare, - NULL, - file_cmd_cleanup + .cmds = { + .prepare = file_cmd_prepare, + .cleanup = file_cmd_cleanup }, - fileio_args, - {0,0} + .args = fileio_args }; @@ -281,8 +276,8 @@ static int remove_files(void); static int parse_arguments(void); static void clear_stats(void); static void init_vars(void); -static sb_request_t file_get_seq_request(void); -static sb_request_t file_get_rnd_request(int thread_id); +static sb_event_t file_get_seq_request(void); +static sb_event_t file_get_rnd_request(int thread_id); static void check_seq_req(sb_file_request_t *, sb_file_request_t *); static const char *get_io_mode_str(file_io_mode_t mode); static const char *get_test_mode_str(file_test_mode_t mode); @@ -418,7 +413,7 @@ int file_done(void) return 0; } -sb_request_t file_get_request(int thread_id) +sb_event_t file_next_event(int thread_id) { if (test_mode == MODE_WRITE || test_mode == MODE_REWRITE || test_mode == MODE_READ) @@ -432,9 +427,9 @@ sb_request_t file_get_request(int thread_id) /* Get sequential read or write request */ -sb_request_t file_get_seq_request(void) +sb_event_t file_get_seq_request(void) { - sb_request_t sb_req; + sb_event_t sb_req; sb_file_request_t *file_req = &sb_req.u.file_request; sb_req.type = SB_REQ_TYPE_FILE; @@ -537,9 +532,9 @@ sb_request_t file_get_seq_request(void) /* Request generatior for random tests */ -sb_request_t file_get_rnd_request(int thread_id) +sb_event_t file_get_rnd_request(int thread_id) { - sb_request_t sb_req; + sb_event_t sb_req; sb_file_request_t *file_req = &sb_req.u.file_request; unsigned long long tmppos; int real_mode = test_mode; @@ -648,12 +643,10 @@ retry: } -int file_execute_request(sb_request_t *sb_req, int thread_id) +int file_execute_event(sb_event_t *sb_req, int thread_id) { FILE_DESCRIPTOR fd; sb_file_request_t *file_req = &sb_req->u.file_request; - log_msg_t msg; - log_msg_oper_t op_msg; if (sb_globals.debug) { @@ -678,9 +671,6 @@ int file_execute_request(sb_request_t *sb_req, int thread_id) return 1; } fd = files[file_req->file_id]; - /* Prepare log message */ - msg.type = LOG_MSG_TYPE_OPER; - msg.data = &op_msg; switch (file_req->operation) { case FILE_OP_TYPE_NULL: @@ -692,7 +682,6 @@ int file_execute_request(sb_request_t *sb_req, int thread_id) if (sb_globals.validate) file_fill_buffer(per_thread[thread_id].buffer, file_req->size, file_req->pos); - LOG_EVENT_START(msg, thread_id); if(file_pwrite(file_req->file_id, per_thread[thread_id].buffer, file_req->size, file_req->pos, thread_id) != (ssize_t)file_req->size) @@ -716,8 +705,6 @@ int file_execute_request(sb_request_t *sb_req, int thread_id) SB_THREAD_MUTEX_UNLOCK(); } - LOG_EVENT_STOP(msg, thread_id); - sb_percentile_update(&local_percentile, sb_timer_value(&timers[thread_id])); @@ -732,7 +719,6 @@ int file_execute_request(sb_request_t *sb_req, int thread_id) break; case FILE_OP_TYPE_READ: - LOG_EVENT_START(msg, thread_id); if(file_pread(file_req->file_id, per_thread[thread_id].buffer, file_req->size, file_req->pos, thread_id) != (ssize_t)file_req->size) @@ -741,7 +727,6 @@ int file_execute_request(sb_request_t *sb_req, int thread_id) fd, (long long)file_req->pos); return 1; } - LOG_EVENT_STOP(msg, thread_id); sb_percentile_update(&local_percentile, sb_timer_value(&timers[thread_id])); diff --git a/sysbench/tests/memory/sb_memory.c b/sysbench/tests/memory/sb_memory.c index 3f28591..502e352 100644 --- a/sysbench/tests/memory/sb_memory.c +++ b/sysbench/tests/memory/sb_memory.c @@ -1,5 +1,5 @@ /* Copyright (C) 2004 MySQL AB - Copyright (C) 2004-2015 Alexey Kopytov + Copyright (C) 2004-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -57,34 +57,22 @@ static sb_arg_t memory_args[] = /* Memory test operations */ static int memory_init(void); static void memory_print_mode(void); -static sb_request_t memory_get_request(int); -static int memory_execute_request(sb_request_t *, int); +static sb_event_t memory_next_event(int); +static int memory_execute_event(sb_event_t *, int); static void memory_print_stats(sb_stat_t type); static sb_test_t memory_test = { - "memory", - "Memory functions speed test", - { - memory_init, - NULL, - NULL, - memory_print_mode, - memory_get_request, - memory_execute_request, - memory_print_stats, - NULL, - NULL, - NULL + .sname = "memory", + .lname = "Memory functions speed test", + .ops = { + .init = memory_init, + .print_mode = memory_print_mode, + .next_event = memory_next_event, + .execute_event = memory_execute_event, + .print_stats = memory_print_stats }, - { - NULL, - NULL, - NULL, - NULL - }, - memory_args, - {NULL, NULL} + .args = memory_args }; /* Test arguments */ @@ -218,9 +206,9 @@ int memory_init(void) } -sb_request_t memory_get_request(int thread_id) +sb_event_t memory_next_event(int thread_id) { - sb_request_t req; + sb_event_t req; sb_mem_request_t *mem_req = &req.u.mem_request; (void) thread_id; /* unused */ @@ -244,20 +232,14 @@ sb_request_t memory_get_request(int thread_id) return req; } -int memory_execute_request(sb_request_t *sb_req, int thread_id) +int memory_execute_event(sb_event_t *sb_req, int thread_id) { sb_mem_request_t *mem_req = &sb_req->u.mem_request; volatile int tmp = 0; int idx; int *buf, *end; - log_msg_t msg; - log_msg_oper_t op_msg; long i; - /* Prepare log message */ - msg.type = LOG_MSG_TYPE_OPER; - msg.data = &op_msg; - if (mem_req->scope == SB_MEM_SCOPE_GLOBAL) buf = buffer; else @@ -266,7 +248,6 @@ int memory_execute_request(sb_request_t *sb_req, int thread_id) if (memory_access_rnd) { - LOG_EVENT_START(msg, thread_id); switch (mem_req->type) { case SB_MEM_OP_WRITE: for (i = 0; i < memory_block_size; i++) @@ -290,7 +271,6 @@ int memory_execute_request(sb_request_t *sb_req, int thread_id) } else { - LOG_EVENT_START(msg, thread_id); switch (mem_req->type) { case SB_MEM_OP_NONE: for (; buf < end; buf++) @@ -310,8 +290,6 @@ int memory_execute_request(sb_request_t *sb_req, int thread_id) return 1; } } - - LOG_EVENT_STOP(msg, thread_id); return 0; } diff --git a/sysbench/tests/mutex/sb_mutex.c b/sysbench/tests/mutex/sb_mutex.c index 01d1b01..a27e243 100644 --- a/sysbench/tests/mutex/sb_mutex.c +++ b/sysbench/tests/mutex/sb_mutex.c @@ -1,5 +1,5 @@ /* Copyright (C) 2004 MySQL AB - Copyright (C) 2004-2008 Alexey Kopytov + Copyright (C) 2004-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,34 +51,22 @@ static sb_arg_t mutex_args[] = /* Mutex test operations */ static int mutex_init(void); static void mutex_print_mode(void); -static sb_request_t mutex_get_request(int); -static int mutex_execute_request(sb_request_t *, int); +static sb_event_t mutex_next_event(int); +static int mutex_execute_event(sb_event_t *, int); static int mutex_done(void); static sb_test_t mutex_test = { - "mutex", - "Mutex performance test", - { - mutex_init, - NULL, - NULL, - mutex_print_mode, - mutex_get_request, - mutex_execute_request, - NULL, - NULL, - NULL, - mutex_done + .sname = "mutex", + .lname = "Mutex performance test", + .ops = { + .init = mutex_init, + .print_mode = mutex_print_mode, + .next_event = mutex_next_event, + .execute_event = mutex_execute_event, + .done = mutex_done }, - { - NULL, - NULL, - NULL, - NULL - }, - mutex_args, - {NULL, NULL} + .args = mutex_args }; @@ -130,9 +118,9 @@ int mutex_done(void) } -sb_request_t mutex_get_request(int thread_id) +sb_event_t mutex_next_event(int thread_id) { - sb_request_t sb_req; + sb_event_t sb_req; sb_mutex_request_t *mutex_req = &sb_req.u.mutex_request; (void) thread_id; /* unused */ @@ -145,20 +133,15 @@ sb_request_t mutex_get_request(int thread_id) } -int mutex_execute_request(sb_request_t *sb_req, int thread_id) +int mutex_execute_event(sb_event_t *sb_req, int thread_id) { unsigned int i; unsigned int c=0; unsigned int current_lock; sb_mutex_request_t *mutex_req = &sb_req->u.mutex_request; - log_msg_t msg; - log_msg_oper_t op_msg; - /* Prepare log message */ - msg.type = LOG_MSG_TYPE_OPER; - msg.data = &op_msg; + (void) thread_id; /* unused */ - LOG_EVENT_START(msg, thread_id); do { current_lock = rand() % mutex_num; @@ -170,7 +153,6 @@ int mutex_execute_request(sb_request_t *sb_req, int thread_id) mutex_req->nlocks--; } while (mutex_req->nlocks > 0); - LOG_EVENT_STOP(msg, thread_id); /* Perform only one request per thread */ return 1; diff --git a/sysbench/tests/threads/sb_threads.c b/sysbench/tests/threads/sb_threads.c index b677d41..462c952 100644 --- a/sysbench/tests/threads/sb_threads.c +++ b/sysbench/tests/threads/sb_threads.c @@ -1,5 +1,5 @@ /* Copyright (C) 2004 MySQL AB - Copyright (C) 2004-2015 Alexey Kopytov + Copyright (C) 2004-2016 Alexey Kopytov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -54,34 +54,23 @@ static sb_arg_t threads_args[] = static int threads_init(void); static int threads_prepare(void); static void threads_print_mode(void); -static sb_request_t threads_get_request(int); -static int threads_execute_request(sb_request_t *, int); +static sb_event_t threads_next_event(int); +static int threads_execute_event(sb_event_t *, int); static int threads_cleanup(void); static sb_test_t threads_test = { - "threads", - "Threads subsystem performance test", - { - threads_init, - threads_prepare, - NULL, - threads_print_mode, - threads_get_request, - threads_execute_request, - NULL, - NULL, - NULL, - threads_cleanup, + .sname = "threads", + .lname = "Threads subsystem performance test", + .ops = { + .init = threads_init, + .prepare = threads_prepare, + .print_mode = threads_print_mode, + .next_event = threads_next_event, + .execute_event = threads_execute_event, + .cleanup = threads_cleanup }, - { - NULL, - NULL, - NULL, - NULL - }, - threads_args, - {NULL, NULL} + .args = threads_args }; static unsigned int thread_yields; @@ -139,9 +128,9 @@ int threads_cleanup(void) } -sb_request_t threads_get_request(int thread_id) +sb_event_t threads_next_event(int thread_id) { - sb_request_t sb_req; + sb_event_t sb_req; sb_threads_request_t *threads_req = &sb_req.u.threads_request; (void) thread_id; /* unused */ @@ -163,25 +152,19 @@ sb_request_t threads_get_request(int thread_id) } -int threads_execute_request(sb_request_t *sb_req, int thread_id) +int threads_execute_event(sb_event_t *sb_req, int thread_id) { unsigned int i; sb_threads_request_t *threads_req = &sb_req->u.threads_request; - log_msg_t msg; - log_msg_oper_t op_msg; - - /* Prepare log message */ - msg.type = LOG_MSG_TYPE_OPER; - msg.data = &op_msg; - LOG_EVENT_START(msg, thread_id); + (void) thread_id; /* unused */ + for(i = 0; i < thread_yields; i++) { pthread_mutex_lock(&test_mutexes[threads_req->lock_num]); YIELD(); pthread_mutex_unlock(&test_mutexes[threads_req->lock_num]); } - LOG_EVENT_STOP(msg, thread_id); return 0; } diff --git a/tests/t/test_fileio.t b/tests/t/test_fileio.t index 4f7d07f..94d005e 100644 --- a/tests/t/test_fileio.t +++ b/tests/t/test_fileio.t @@ -68,7 +68,7 @@ fileio benchmark tests General statistics: total time: *.*s (glob) - total number of events: 150 + total number of events: 158 total time taken by event execution: *.*s (glob) response time: min: *.*ms (glob) @@ -77,7 +77,7 @@ fileio benchmark tests approx. 95 percentile: *.*ms (glob) Threads fairness: - events (avg/stddev): 150.0000/0.00 + events (avg/stddev): 158.0000/0.00 execution time (avg/stddev): *.*/0.00 (glob) $ sysbench $fileio_args --max-requests=150 --file-test-mode=rndrd run @@ -206,7 +206,7 @@ fileio benchmark tests General statistics: total time: *.*s (glob) - total number of events: 150 + total number of events: 158 total time taken by event execution: *.*s (glob) response time: min: *.*ms (glob) @@ -215,7 +215,7 @@ fileio benchmark tests approx. 95 percentile: *.*ms (glob) Threads fairness: - events (avg/stddev): 150.0000/0.00 + events (avg/stddev): 158.0000/0.00 execution time (avg/stddev): *.*/0.00 (glob) From 7bc9a0622fad0e9614c5a8da7b357826805d2b8c Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Sun, 18 Dec 2016 22:18:58 +0800 Subject: [PATCH 8/8] Fix tests, remove thread_id arg from Lua API functions. --- sysbench/lua/internal/sysbench.lua | 2 ++ sysbench/tests/db/bulk_insert.lua | 2 +- sysbench/tests/db/delete.lua | 4 ++-- sysbench/tests/db/insert.lua | 2 +- sysbench/tests/db/oltp.lua | 4 ++-- sysbench/tests/db/oltp_simple.lua | 4 ++-- sysbench/tests/db/parallel_prepare.lua | 4 ++-- sysbench/tests/db/select.lua | 4 ++-- sysbench/tests/db/select_random_points.lua | 4 ++-- sysbench/tests/db/select_random_ranges.lua | 4 ++-- sysbench/tests/db/update_index.lua | 4 ++-- sysbench/tests/db/update_non_index.lua | 4 ++-- tests/t/script_oltp_mysql.t | 8 ++++---- tests/t/script_oltp_pgsql.t | 4 ++-- tests/t/script_select_random_pgsql.t | 6 +++--- 15 files changed, 31 insertions(+), 29 deletions(-) diff --git a/sysbench/lua/internal/sysbench.lua b/sysbench/lua/internal/sysbench.lua index 4775aa4..0e7d9b5 100644 --- a/sysbench/lua/internal/sysbench.lua +++ b/sysbench/lua/internal/sysbench.lua @@ -18,6 +18,8 @@ -- Compatibility aliases. These may be removed in later versions -- ---------------------------------------------------------------------- +thread_id = sysbench.tid + sb_rand = sysbench.rand sb_rand_uniq = sb_rand_uniq sb_rnd = sysbench.rnd diff --git a/sysbench/tests/db/bulk_insert.lua b/sysbench/tests/db/bulk_insert.lua index cfdc208..d203f78 100644 --- a/sysbench/tests/db/bulk_insert.lua +++ b/sysbench/tests/db/bulk_insert.lua @@ -35,7 +35,7 @@ PRIMARY KEY (id) end --for end -function event(thread_id) +function event() local i if (cursize == 0) then diff --git a/sysbench/tests/db/delete.lua b/sysbench/tests/db/delete.lua index 85c9c94..68a85a0 100644 --- a/sysbench/tests/db/delete.lua +++ b/sysbench/tests/db/delete.lua @@ -6,11 +6,11 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars() end -function event(thread_id) +function event() local table_name table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count) rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. sb_rand(1, oltp_table_size)) diff --git a/sysbench/tests/db/insert.lua b/sysbench/tests/db/insert.lua index 60e9567..263ee6f 100644 --- a/sysbench/tests/db/insert.lua +++ b/sysbench/tests/db/insert.lua @@ -10,7 +10,7 @@ function thread_init(thread_id) set_vars() end -function event(thread_id) +function event() local table_name local i local c_val diff --git a/sysbench/tests/db/oltp.lua b/sysbench/tests/db/oltp.lua index 209f5a9..66ef667 100644 --- a/sysbench/tests/db/oltp.lua +++ b/sysbench/tests/db/oltp.lua @@ -6,7 +6,7 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars() if (((db_driver == "mysql") or (db_driver == "attachsql")) and mysql_table_engine == "myisam") then @@ -30,7 +30,7 @@ function get_range_str() start, start + oltp_range_size - 1) end -function event(thread_id) +function event() local rs local i local table_name diff --git a/sysbench/tests/db/oltp_simple.lua b/sysbench/tests/db/oltp_simple.lua index c55cc57..a2a5b82 100644 --- a/sysbench/tests/db/oltp_simple.lua +++ b/sysbench/tests/db/oltp_simple.lua @@ -6,12 +6,12 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars() end -function event(thread_id) +function event() local table_name table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count) diff --git a/sysbench/tests/db/parallel_prepare.lua b/sysbench/tests/db/parallel_prepare.lua index d001310..b2cda7a 100644 --- a/sysbench/tests/db/parallel_prepare.lua +++ b/sysbench/tests/db/parallel_prepare.lua @@ -8,11 +8,11 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars() end -function event(thread_id) +function event() local index_name local i print("thread prepare"..thread_id) diff --git a/sysbench/tests/db/select.lua b/sysbench/tests/db/select.lua index b2a75f6..571ef21 100644 --- a/sysbench/tests/db/select.lua +++ b/sysbench/tests/db/select.lua @@ -6,11 +6,11 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars() end -function event(thread_id) +function event() local table_name table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count) rs = db_query("SELECT pad FROM ".. table_name .." WHERE id=" .. sb_rand(1, oltp_table_size)) diff --git a/sysbench/tests/db/select_random_points.lua b/sysbench/tests/db/select_random_points.lua index 5f426c8..de18376 100644 --- a/sysbench/tests/db/select_random_points.lua +++ b/sysbench/tests/db/select_random_points.lua @@ -16,7 +16,7 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars_points() points = "" @@ -41,7 +41,7 @@ function thread_init(thread_id) db_bind_param(stmt, params) end -function event(thread_id) +function event() local rs -- To prevent overlapping of our range queries we need to partition the whole table diff --git a/sysbench/tests/db/select_random_ranges.lua b/sysbench/tests/db/select_random_ranges.lua index b67d774..6185100 100644 --- a/sysbench/tests/db/select_random_ranges.lua +++ b/sysbench/tests/db/select_random_ranges.lua @@ -16,7 +16,7 @@ end -- Override oltp_tables_count, this test only supports a single table oltp_tables_count = 1 -function thread_init(thread_id) +function thread_init() set_vars_ranges() ranges = "" @@ -42,7 +42,7 @@ function thread_init(thread_id) end -function event(thread_id) +function event() local rs -- To prevent overlapping of our range queries we need to partition the whole table diff --git a/sysbench/tests/db/update_index.lua b/sysbench/tests/db/update_index.lua index 077240c..5d1f20c 100644 --- a/sysbench/tests/db/update_index.lua +++ b/sysbench/tests/db/update_index.lua @@ -6,11 +6,11 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars() end -function event(thread_id) +function event() local table_name table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count) rs = db_query("UPDATE ".. table_name .." SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size)) diff --git a/sysbench/tests/db/update_non_index.lua b/sysbench/tests/db/update_non_index.lua index 1a6a502..d549add 100644 --- a/sysbench/tests/db/update_non_index.lua +++ b/sysbench/tests/db/update_non_index.lua @@ -6,11 +6,11 @@ else require("common") end -function thread_init(thread_id) +function thread_init() set_vars() end -function event(thread_id) +function event() local table_name local c_val local query diff --git a/tests/t/script_oltp_mysql.t b/tests/t/script_oltp_mysql.t index f6988a5..a06be2c 100644 --- a/tests/t/script_oltp_mysql.t +++ b/tests/t/script_oltp_mysql.t @@ -175,7 +175,7 @@ oltp.lua + MySQL tests 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 *: multi-threaded system evaluation benchmark (glob) + sysbench * (glob) Creating table 'sbtest1'... Inserting 10000 records into 'sbtest1' @@ -188,7 +188,7 @@ oltp.lua + MySQL tests `pad` char(60)* NOT NULL DEFAULT '', (glob) PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob) - sysbench *: multi-threaded system evaluation benchmark (glob) + sysbench * (glob) Dropping table 'sbtest1'... @@ -356,7 +356,7 @@ oltp.lua + MySQL tests 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 *: multi-threaded system evaluation benchmark (glob) + sysbench * (glob) Creating table 'sbtest1'... Inserting 10000 records into 'sbtest1' @@ -369,6 +369,6 @@ oltp.lua + MySQL tests `pad` char(60)* NOT NULL DEFAULT '', (glob) PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=* MAX_ROWS=1000000 (glob) - sysbench *: multi-threaded system evaluation benchmark (glob) + sysbench * (glob) Dropping table 'sbtest1'... diff --git a/tests/t/script_oltp_pgsql.t b/tests/t/script_oltp_pgsql.t index 4e3c73a..37def2b 100644 --- a/tests/t/script_oltp_pgsql.t +++ b/tests/t/script_oltp_pgsql.t @@ -184,7 +184,7 @@ oltp.lua + PostgreSQL tests Did not find any relation named "sbtest6". Did not find any relation named "sbtest7". Did not find any relation named "sbtest8". - sysbench 1.0: multi-threaded system evaluation benchmark (glob) + sysbench * (glob) Creating table 'sbtest1'... Inserting 10000 records into 'sbtest1' @@ -198,6 +198,6 @@ oltp.lua + PostgreSQL tests Indexes: "sbtest1_pkey" PRIMARY KEY, btree (id) - sysbench *: multi-threaded system evaluation benchmark (glob) + sysbench * (glob) Dropping table 'sbtest1'... diff --git a/tests/t/script_select_random_pgsql.t b/tests/t/script_select_random_pgsql.t index 49761c9..2c27ec9 100644 --- a/tests/t/script_select_random_pgsql.t +++ b/tests/t/script_select_random_pgsql.t @@ -13,7 +13,7 @@ select_random_*.lua + PostgreSQL tests $ DB_DRIVER_ARGS="--db-driver=pgsql $SBTEST_PGSQL_ARGS" $ . $SBTEST_INCDIR/script_select_random_common.sh - sysbench 1.0: multi-threaded system evaluation benchmark + sysbench * (glob) Creating table 'sbtest1'... Inserting 10000 records into 'sbtest1' @@ -84,7 +84,7 @@ select_random_*.lua + PostgreSQL tests Did not find any relation named "sbtest6". Did not find any relation named "sbtest7". Did not find any relation named "sbtest8". - sysbench 1.0: multi-threaded system evaluation benchmark + sysbench * (glob) Creating table 'sbtest1'... Inserting 10000 records into 'sbtest1' @@ -144,7 +144,7 @@ select_random_*.lua + PostgreSQL tests events (avg/stddev):* (glob) execution time (avg/stddev):* (glob) - sysbench 1.0: multi-threaded system evaluation benchmark + sysbench * (glob) Dropping table 'sbtest1'... Did not find any relation named "sbtest1".