Merge lp:~alexey2k/sysbench/sb-prepared-stmt into lp:sysbench

Proposed by Alexey Kopytov
Status: Needs review
Proposed branch: lp:~alexey2k/sysbench/sb-prepared-stmt
Merge into: lp:sysbench
Diff against target: 455 lines (+301/-80)
3 files modified
sysbench/tests/db/common.lua (+78/-8)
sysbench/tests/db/oltp.lua (+10/-72)
sysbench/tests/db/oltp_common.lua (+213/-0)
To merge this branch: bzr merge lp:~alexey2k/sysbench/sb-prepared-stmt
Reviewer Review Type Date Requested Status
Alexey Kopytov Pending
Review via email: mp+152934@code.launchpad.net

Description of the change

Lua implementation of OLTP workload with prepared statement
Added help information
Various cleanups and minor fixes

To post a comment you must log in.

Unmerged revisions

117. By Alexey Stroganov

Lua implementation of OLTP workload with prepared statement
Added help information
Various cleanups and minor fixes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sysbench/tests/db/common.lua'
2--- sysbench/tests/db/common.lua 2011-12-01 19:43:29 +0000
3+++ sysbench/tests/db/common.lua 2013-03-12 15:16:22 +0000
4@@ -19,7 +19,7 @@
5
6 i = table_id
7
8- print("Creating table 'sbtest" .. i .. "'...")
9+ print("Creating table '" .. oltp_table_name .. i .. "'...")
10 if (db_driver == "mysql") then
11 query = [[
12 CREATE TABLE sbtest]] .. i .. [[ (
13@@ -58,14 +58,14 @@
14
15 db_query(query)
16
17- db_query("CREATE INDEX k_" .. i .. " on sbtest" .. i .. "(k)")
18+ db_query("CREATE INDEX k_" .. i .. " on ".. oltp_table_name .. i .. "(k)")
19
20- print("Inserting " .. oltp_table_size .. " records into 'sbtest" .. i .. "'")
21+ print("Inserting " .. oltp_table_size .. " records into '" .. oltp_table_name .. i .. "'")
22
23 if (oltp_auto_inc) then
24- db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(k, c, pad) VALUES")
25+ db_bulk_insert_init("INSERT INTO " .. oltp_table_name .. i .. "(k, c, pad) VALUES")
26 else
27- db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(id, k, c, pad) VALUES")
28+ db_bulk_insert_init("INSERT INTO " .. oltp_table_name .. i .. "(id, k, c, pad) VALUES")
29 end
30
31 local c_val
32@@ -101,7 +101,6 @@
33
34 db_connect()
35
36-
37 for i = 1,oltp_tables_count do
38 create_insert(i)
39 end
40@@ -115,7 +114,7 @@
41 set_vars()
42
43 for i = 1,oltp_tables_count do
44- print("Dropping table 'sbtest" .. i .. "'...")
45+ print("Dropping table '" .. oltp_table_name .. i .. "'...")
46 db_query("DROP TABLE sbtest".. i )
47 end
48 end
49@@ -131,6 +130,18 @@
50 oltp_distinct_ranges = oltp_distinct_ranges or 1
51 oltp_index_updates = oltp_index_updates or 1
52 oltp_non_index_updates = oltp_non_index_updates or 1
53+ oltp_delete = 1
54+ oltp_insert = 1
55+
56+ prepared_stmt_mode=true
57+
58+ if (oltp_ps_mode == 'disable') then
59+ prepared_stmt_mode=false
60+ end
61+
62+ if (oltp_table_name == nil or oltp_table_name == '' ) then
63+ oltp_table_name = 'sbtest'
64+ end
65
66 if (oltp_auto_inc == 'off') then
67 oltp_auto_inc = false
68@@ -150,4 +161,63 @@
69 oltp_skip_trx = false
70 end
71
72-end
73+ if (oltp_secondary == 'on') then
74+ oltp_secondary = true
75+ else
76+ oltp_secondary = false
77+ end
78+
79+end
80+
81+function help()
82+
83+ print ([[
84+
85+ --oltp_table_name = <default:sbtest>
86+ --oltp_table_size = <default:10000>
87+ --oltp_tables_count = <default:1>
88+
89+ --oltp_range_size = <default:100>
90+ --oltp_point_selects = <default:10>
91+ --oltp_simple_ranges = <default:1>
92+ --oltp_sum_ranges = <default:1>
93+ --oltp_order_ranges = <default:1>
94+ --oltp_distinct_ranges = <default:1>
95+ --oltp_index_updates = <default:1>
96+ --oltp_non_index_updates = <default:1>
97+ --oltp_delete = <default:1>
98+ --oltp_insert = <default:1>
99+
100+
101+
102+ --oltp_read_only = <on|off>
103+ --oltp_skip_trx = <on|off>
104+ --oltp_auto_inc = <on|off>
105+ --oltp_secondary = <on|off> use secondary key instead PRIMARY key for id column
106+
107+ --oltp-ps-mode = <enable|disable>
108+ --mysql_table_engine = <default:InnoDB>
109+ --mysql-host = <default:localhost> MySQL server host, you may specify a list of hosts separated by commas. In this case
110+ SysBench will distribute connections between specified MySQL hosts on a round-robin basis.
111+ Note that all connection ports and passwords must be the same on all hosts.
112+ Also, databases and tables must be prepared explicitely on each host before
113+ executing the benchmark.
114+ --mysql-port = <default:3306> MySQL server port (in case TCP/IP connection should be used)
115+ --mysql-socket = <> Unix socket file to communicate with the MySQL server
116+ --mysql-user = <> MySQL user
117+ --mysql-password = <> MySQL password
118+ --mysql-db = <sbtest> MySQL database name. Note SysBench will not automatically create this database.
119+ You should create it manually and grant the appropriate privileges to a user which will
120+ be used to access the test table
121+ --mysql-table-engine = <innodb> Type of the test table. Possible values: myisam, innodb, heap, ndbcluster
122+ --mysql-ssl = <no> Use SSL connections
123+ --myisam-max-rows = <1000000> MAX_ROWS option for MyISAM tables (required for big tables) 1000000
124+ --mysql-create-options = <> Additional options passed to CREATE TABLE.
125+
126+ ]])
127+
128+end
129+
130+
131+
132+
133\ No newline at end of file
134
135=== modified file 'sysbench/tests/db/oltp.lua'
136--- sysbench/tests/db/oltp.lua 2011-12-01 19:43:29 +0000
137+++ sysbench/tests/db/oltp.lua 2013-03-12 15:16:22 +0000
138@@ -1,89 +1,27 @@
139 pathtest = string.match(test, "(.*/)") or ""
140
141 dofile(pathtest .. "common.lua")
142+dofile(pathtest .. "oltp_common.lua")
143
144 function thread_init(thread_id)
145 set_vars()
146
147- if (db_driver == "mysql" and mysql_table_engine == "myisam") then
148- begin_query = "LOCK TABLES sbtest WRITE"
149- commit_query = "UNLOCK TABLES"
150+ if (prepared_stmt_mode) then
151+ init_prepared_stmt()
152 else
153- begin_query = "BEGIN"
154- commit_query = "COMMIT"
155+ init_plain_stmt()
156 end
157
158 end
159
160 function event(thread_id)
161- local rs
162- local i
163- local table_name
164- local range_start
165- local c_val
166- local pad_val
167- local query
168-
169- table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
170- if not oltp_skip_trx then
171- db_query(begin_query)
172- end
173-
174- for i=1, oltp_point_selects do
175- rs = db_query("SELECT c FROM ".. table_name .." WHERE id=" .. sb_rand(1, oltp_table_size))
176- end
177-
178- for i=1, oltp_simple_ranges do
179- range_start = sb_rand(1, oltp_table_size)
180- rs = db_query("SELECT c FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1)
181- end
182-
183- for i=1, oltp_sum_ranges do
184- range_start = sb_rand(1, oltp_table_size)
185- rs = db_query("SELECT SUM(K) FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1)
186- end
187-
188- for i=1, oltp_order_ranges do
189- range_start = sb_rand(1, oltp_table_size)
190- rs = db_query("SELECT c FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1 .. " ORDER BY c")
191- end
192-
193- for i=1, oltp_distinct_ranges do
194- range_start = sb_rand(1, oltp_table_size)
195- rs = db_query("SELECT DISTINCT c FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1 .. " ORDER BY c")
196- end
197-
198- if not oltp_read_only then
199-
200- for i=1, oltp_index_updates do
201- rs = db_query("UPDATE " .. table_name .. " SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size))
202- end
203-
204- for i=1, oltp_non_index_updates do
205- c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
206- query = "UPDATE " .. table_name .. " SET c='" .. c_val .. "' WHERE id=" .. sb_rand(1, oltp_table_size)
207- rs = db_query(query)
208- if rs then
209- print(query)
210- end
211- end
212-
213- i = sb_rand(1, oltp_table_size)
214-
215- rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. i)
216-
217- c_val = sb_rand_str([[
218-###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
219- pad_val = sb_rand_str([[
220-###########-###########-###########-###########-###########]])
221-
222- rs = db_query("INSERT INTO " .. table_name .. " (id, k, c, pad) VALUES " .. string.format("(%d, %d, '%s', '%s')",i, sb_rand(1, oltp_table_size) , c_val, pad_val))
223-
224- end -- oltp_read_only
225-
226- if not oltp_skip_trx then
227- db_query(commit_query)
228+
229+ if (prepared_stmt_mode) then
230+ event_prepared_stmt(thread_id)
231+ else
232+ event_plain_stmt(thread_id)
233 end
234
235 end
236
237+
238
239=== added file 'sysbench/tests/db/oltp_common.lua'
240--- sysbench/tests/db/oltp_common.lua 1970-01-01 00:00:00 +0000
241+++ sysbench/tests/db/oltp_common.lua 2013-03-12 15:16:22 +0000
242@@ -0,0 +1,213 @@
243+function init_prepared_stmt()
244+
245+ stmt= {
246+ point= { query = "SELECT c FROM sb_table_name WHERE id=?", params_template = {0}, params={}, sth = {} },
247+ range= { query = "SELECT c FROM sb_table_name WHERE id BETWEEN ? AND ?", params_template = {0, 0}, params={}, sth = {} },
248+ sum= { query = "SELECT SUM(K) FROM sb_table_name WHERE id BETWEEN ? AND ?", params_template = {0, 0}, params={}, sth = {} },
249+ order= { query = "SELECT c FROM sb_table_name WHERE id BETWEEN ? AND ? ORDER BY c", params_template = { 0, 0}, params={}, sth = {} },
250+ distinct= { query = "SELECT DISTINCT c FROM sb_table_name WHERE id BETWEEN ? AND ? ORDER BY c", params_template = {0, 0}, params={}, sth = {} },
251+ update_idx= { query = "UPDATE sb_table_name SET k=k+1 WHERE id=?", params_template = {0}, params={}, sth = {} },
252+ update_non_idx= { query = "UPDATE sb_table_name SET c=? WHERE id=?", params_template = {"", 0}, params={}, sth = {} },
253+ delete= { query = "DELETE FROM sb_table_name WHERE id=?", params_template = {0}, params={}, sth = {} },
254+ insert= { query = "INSERT INTO sb_table_name (id, k, c, pad) VALUES (?, ?, ? , ?)", params_template = {0,0,"",""}, params={}, sth = {} },
255+ begin= { query = "BEGIN", params_template = {}, params={}, sth = {} },
256+ commit= { query = "COMMIT", params_template = {}, params={}, sth = {} }
257+ }
258+
259+ if (db_driver == "mysql" and mysql_table_engine == "myisam") then
260+ stmt["begin"]["query"]="LOCK TABLES sb_table_name WRITE"
261+ stmt["commit"]["query"]="UNLOCK TABLES"
262+ end
263+
264+ for t1,t2 in pairs (stmt) do
265+ for i=1, oltp_tables_count do
266+ local query=t2["query"]
267+ query=query:gsub("sb_table_name", oltp_table_name..i)
268+ t2["sth"][i]=db_prepare(query)
269+ if ( t2["params_template"][1] ~= nil ) then
270+ t2["params"][i]={}
271+ for j,x in ipairs(t2["params_template"]) do t2["params"][i][j] = x end
272+ db_bind_param(t2["sth"][i], t2["params"][i])
273+ end
274+ end
275+ end
276+end
277+
278+
279+function init_plain_stmt()
280+
281+ if (db_driver == "mysql" and mysql_table_engine == "myisam") then
282+ begin_query = "LOCK TABLES sbtest WRITE"
283+ commit_query = "UNLOCK TABLES"
284+ else
285+ begin_query = "BEGIN"
286+ commit_query = "COMMIT"
287+ end
288+end
289+
290+
291+function sth_execute(sth)
292+ rs = db_execute(sth)
293+ db_store_results(rs)
294+ db_free_results(rs)
295+end
296+
297+function event_prepared_stmt(thread_id)
298+ local rs
299+ local i
300+ local table_name
301+ local range_start
302+ local c_val
303+ local pad_val
304+ local query
305+
306+ table_id = sb_rand_uniform(1, oltp_tables_count)
307+
308+ if not oltp_skip_trx then
309+ db_execute(stmt["begin"]["sth"][table_id])
310+ end
311+
312+ for i=1, oltp_point_selects do
313+ stmt["point"]["params"][table_id][1] = sb_rand(1, oltp_table_size)
314+ sth_execute(stmt["point"]["sth"][table_id])
315+ end
316+
317+ for i=1, oltp_simple_ranges do
318+ stmt["range"]["params"][table_id][1] = sb_rand(1, oltp_table_size)
319+ stmt["range"]["params"][table_id][2] = stmt["range"]["params"][table_id][1] + oltp_range_size - 1
320+ sth_execute(stmt["range"]["sth"][table_id])
321+ end
322+
323+ for i=1, oltp_sum_ranges do
324+ stmt["sum"]["params"][table_id][1] = sb_rand(1, oltp_table_size)
325+ stmt["sum"]["params"][table_id][2] = stmt["sum"]["params"][table_id][1] + oltp_range_size - 1
326+ sth_execute(stmt["sum"]["sth"][table_id])
327+ end
328+
329+ for i=1, oltp_order_ranges do
330+ stmt["order"]["params"][table_id][1] = sb_rand(1, oltp_table_size)
331+ stmt["order"]["params"][table_id][2] = stmt["order"]["params"][table_id][1] + oltp_range_size - 1
332+ sth_execute(stmt["order"]["sth"][table_id])
333+ end
334+
335+ for i=1, oltp_distinct_ranges do
336+ stmt["distinct"]["params"][table_id][1] = sb_rand(1, oltp_table_size)
337+ stmt["distinct"]["params"][table_id][2] = stmt["distinct"]["params"][table_id][1] + oltp_range_size - 1
338+ sth_execute(stmt["distinct"]["sth"][table_id])
339+ end
340+
341+ if not oltp_read_only then
342+
343+ for i=1, oltp_index_updates do
344+ stmt["update_idx"]["params"][table_id][1] = sb_rand(1, oltp_table_size)
345+ db_execute(stmt["update_idx"]["sth"][table_id])
346+ end
347+
348+ for i=1, oltp_non_index_updates do
349+ c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
350+ stmt["update_non_idx"]["params"][table_id][1] = c_val
351+ stmt["update_non_idx"]["params"][table_id][2] = sb_rand(1, oltp_table_size)
352+ db_execute(stmt["update_non_idx"]["sth"][table_id])
353+ end
354+
355+ -- DELETE and INSERT on the same id
356+ local id = sb_rand(1, oltp_table_size)
357+
358+ for i=1, oltp_delete do
359+ stmt["delete"]["params"][table_id][1] = id
360+ db_execute(stmt["delete"]["sth"][table_id])
361+ end
362+
363+ for i=1, oltp_insert do
364+ c_val = sb_rand_str([[###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
365+ pad_val = sb_rand_str([[###########-###########-###########-###########-###########]])
366+
367+ stmt["insert"]["params"][table_id][1] = id
368+ stmt["insert"]["params"][table_id][2] = sb_rand(1, oltp_table_size)
369+ stmt["insert"]["params"][table_id][3] = c_val
370+ stmt["insert"]["params"][table_id][4] = pad_val
371+ db_execute(stmt["insert"]["sth"][table_id])
372+ end
373+ end -- oltp_read_only
374+
375+ if not oltp_skip_trx then
376+ db_execute(stmt["commit"]["sth"][table_id])
377+ end
378+
379+end
380+
381+function event_plain_stmt(thread_id)
382+ local rs
383+ local i
384+ local table_name
385+ local range_start
386+ local c_val
387+ local pad_val
388+ local query
389+
390+ table_name = oltp_table_name .. sb_rand_uniform(1, oltp_tables_count)
391+ if not oltp_skip_trx then
392+ db_query(begin_query)
393+ end
394+
395+ for i=1, oltp_point_selects do
396+ rs = db_query("SELECT c FROM ".. table_name .." WHERE id=" .. sb_rand(1, oltp_table_size))
397+ end
398+
399+ for i=1, oltp_simple_ranges do
400+ range_start = sb_rand(1, oltp_table_size)
401+ rs = db_query("SELECT c FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1)
402+ end
403+
404+ for i=1, oltp_sum_ranges do
405+ range_start = sb_rand(1, oltp_table_size)
406+ rs = db_query("SELECT SUM(K) FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1)
407+ end
408+
409+ for i=1, oltp_order_ranges do
410+ range_start = sb_rand(1, oltp_table_size)
411+ rs = db_query("SELECT c FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1 .. " ORDER BY c")
412+ end
413+
414+ for i=1, oltp_distinct_ranges do
415+ range_start = sb_rand(1, oltp_table_size)
416+ rs = db_query("SELECT DISTINCT c FROM ".. table_name .." WHERE id BETWEEN " .. range_start .. " AND " .. range_start .. "+" .. oltp_range_size - 1 .. " ORDER BY c")
417+ end
418+
419+ if not oltp_read_only then
420+
421+ for i=1, oltp_index_updates do
422+ rs = db_query("UPDATE " .. table_name .. " SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size))
423+ end
424+
425+ for i=1, oltp_non_index_updates do
426+ c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
427+ query = "UPDATE " .. table_name .. " SET c='" .. c_val .. "' WHERE id=" .. sb_rand(1, oltp_table_size)
428+ rs = db_query(query)
429+ if rs then
430+ print(query)
431+ end
432+ end
433+
434+ i = sb_rand(1, oltp_table_size)
435+ for i=1, oltp_delete do
436+ rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. i)
437+ end
438+
439+ for i=1, oltp_insert do
440+ c_val = sb_rand_str([[
441+###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
442+ pad_val = sb_rand_str([[
443+###########-###########-###########-###########-###########]])
444+
445+ rs = db_query("INSERT INTO " .. table_name .. " (id, k, c, pad) VALUES " .. string.format("(%d, %d, '%s', '%s')",i, sb_rand(1, oltp_table_size) , c_val, pad_val))
446+ end
447+
448+ end -- oltp_read_only
449+
450+ if not oltp_skip_trx then
451+ db_query(commit_query)
452+ end
453+
454+end
455+

Subscribers

People subscribed via source and target branches

to status/vote changes: