@@ -9,7 +9,7 @@ local g = t.group('perf')
9
9
10
10
local helpers = require (' test.helper' )
11
11
12
- g .before_all = function ()
12
+ g .before_all ( function (g )
13
13
g .cluster = helpers .Cluster :new ({
14
14
datadir = fio .tempdir (),
15
15
server_command = helpers .entrypoint (' srv_select' ),
@@ -53,21 +53,32 @@ g.before_all = function()
53
53
},
54
54
})
55
55
g .cluster :start ()
56
- end
57
56
58
- g .after_all = function ()
57
+ g .router = g .cluster :server (' router' ).net_box
58
+
59
+ helpers .prepare_simple_functions (g .router )
60
+ g .router :eval (" crud = require('crud') " )
61
+
62
+ -- Run real perf tests only with flag, otherwise run short version
63
+ -- to test compatibility as part of unit/integration test run.
64
+ g .perf_mode_on = os.getenv (' PERF_MODE_ON' )
65
+ end )
66
+
67
+ g .before_each (function (g )
68
+ helpers .truncate_space_on_cluster (g .cluster , ' customers' )
69
+ end )
70
+
71
+ g .after_all (function (g )
59
72
g .cluster :stop ()
60
73
fio .rmtree (g .cluster .datadir )
61
- end
62
-
63
- g .before_each (function () end )
74
+ end )
64
75
65
- local function insert_customers (conn , id , count , timeout , report )
76
+ local function insert_customers (conn , id , count , timeout , report , call_func )
66
77
local customer = {id , box .NULL , ' David' , ' Smith' , 33 , ' Los Angeles' }
67
78
local start = fiber .clock ()
68
79
69
80
while (fiber .clock () - start ) < timeout do
70
- local ok , res , err = pcall (conn .call , conn , [[ package.loaded.crud.insert ]] , {' customers' , customer })
81
+ local ok , res , err = pcall (conn .call , conn , call_func , {' customers' , customer })
71
82
if not ok then
72
83
log .error (' Insert error: %s' , res )
73
84
table.insert (report .errors , res )
@@ -82,11 +93,123 @@ local function insert_customers(conn, id, count, timeout, report)
82
93
end
83
94
end
84
95
85
- local function select_customers (conn , id , timeout , report )
96
+ local insert_cases = {
97
+ without_stats_wrapper = {
98
+ prepare = function (g )
99
+ g .router :eval (" plain_insert = require('crud.insert').tuple" )
100
+ end ,
101
+ call = " plain_insert" ,
102
+ },
103
+ with_stats_disabled = {
104
+ prepare = function (g )
105
+ g .cluster :server (' router' ).net_box :call (" package.loaded.crud.disable_stats" )
106
+ end ,
107
+ call = " package.loaded.crud.insert" ,
108
+ },
109
+ with_local_stats = {
110
+ prepare = function (g )
111
+ g .cluster :server (' router' ).net_box :call (" package.loaded.crud.enable_stats" , {{ driver = ' local' }})
112
+ end ,
113
+ call = " package.loaded.crud.insert" ,
114
+ },
115
+ with_metrics_stats = {
116
+ prepare = function (g )
117
+ local router = g .cluster :server (' router' ).net_box
118
+ local is_metrics_supported = router :eval ([[
119
+ return require('crud.stats.metrics_registry').is_supported()
120
+ ]] )
121
+ t .skip_if (is_metrics_supported == false , ' Metrics registry is unsupported' )
122
+ router :call (" package.loaded.crud.enable_stats" , {{ driver = ' metrics' }})
123
+ end ,
124
+ call = " package.loaded.crud.insert" ,
125
+ },
126
+ }
127
+
128
+ for name , case in pairs (insert_cases ) do
129
+ local test_name = (' test_insert_%s' ):format (name )
130
+
131
+ if case .prepare ~= nil then
132
+ g .before_test (test_name , case .prepare )
133
+ end
134
+
135
+ g [test_name ] = function (g )
136
+ local timeout , fiber_count , connection_count
137
+ if g .perf_mode_on then
138
+ timeout = 30
139
+ fiber_count = 600
140
+ connection_count = 10
141
+ else
142
+ timeout = 2
143
+ fiber_count = 10
144
+ connection_count = 2
145
+ end
146
+
147
+ local connections = {}
148
+
149
+ local server = g .cluster .main_server
150
+ for _ = 1 , connection_count do
151
+ local c = net_box :connect (server .net_box_uri , server .net_box_credentials )
152
+ assert (c )
153
+ table.insert (connections , c )
154
+ end
155
+
156
+ local fibers = {}
157
+ local report = {errors = {}, count = 0 }
158
+ for id = 1 , fiber_count do
159
+ local conn_id = id % connection_count + 1
160
+ local conn = connections [conn_id ]
161
+ local f = fiber .new (insert_customers , conn , id , fiber_count , timeout , report , case .call )
162
+ f :set_joinable (true )
163
+ table.insert (fibers , f )
164
+ end
165
+
166
+ for i = 1 , fiber_count do
167
+ fibers [i ]:join ()
168
+ end
169
+
170
+ log .error (' \n %s: requests %d, rps %d, errors %d' ,
171
+ test_name , report .count , report .count / timeout , # report .errors )
172
+ end
173
+ end
174
+
175
+
176
+ local select_cases = {
177
+ without_stats_wrapper = {
178
+ prepare = function (g )
179
+ g .router :eval (" plain_select = require('crud.select').call" )
180
+ end ,
181
+ call = " plain_select" ,
182
+ },
183
+ with_stats_disabled = {
184
+ prepare = function (g )
185
+ g .router :call (" package.loaded.crud.disable_stats" )
186
+ end ,
187
+ call = " package.loaded.crud.select" ,
188
+ },
189
+ with_local_stats = {
190
+ prepare = function (g )
191
+ g .router :call (" package.loaded.crud.enable_stats" , {{ driver = ' local' }})
192
+ end ,
193
+ call = " package.loaded.crud.select" ,
194
+ },
195
+ with_metrics_stats = {
196
+ prepare = function (g )
197
+ local router = g .cluster :server (' router' ).net_box
198
+ local is_metrics_supported = router :eval ([[
199
+ return require('crud.stats.metrics_registry').is_supported()
200
+ ]] )
201
+ t .skip_if (is_metrics_supported == false , ' Metrics registry is unsupported' )
202
+ router :call (" package.loaded.crud.enable_stats" , {{ driver = ' metrics' }})
203
+ end ,
204
+ call = " package.loaded.crud.select" ,
205
+ },
206
+ }
207
+
208
+ local function select_customers (conn , id , timeout , report , call_func )
86
209
local start = fiber .clock ()
87
210
local ok , err = pcall (function ()
88
211
while (fiber .clock () - start ) < timeout do
89
- local _ , err = conn :call ([[ package.loaded.crud.select ]] , {' customers' , {{' >' , ' id' , id }}, {first = 10 }})
212
+ local _ , err = conn :call (call_func , {' customers' , {{' >' , ' id' , id }}, {first = 10 }})
90
213
if err ~= nil then
91
214
errors .wrap (err )
92
215
log .error (err )
@@ -102,66 +225,50 @@ local function select_customers(conn, id, timeout, report)
102
225
end
103
226
end
104
227
105
- g .test_insert = function ()
106
- local timeout = 30
107
- local fiber_count = 600
108
- local connection_count = 10
109
- local connections = {}
110
-
111
- local server = g .cluster .main_server
112
- server .net_box :eval ([[ require('crud')]] )
113
- for _ = 1 , connection_count do
114
- local c = net_box :connect (server .net_box_uri , server .net_box_credentials )
115
- assert (c )
116
- table.insert (connections , c )
117
- end
228
+ for name , case in pairs (select_cases ) do
229
+ local test_name = (' test_select_%s' ):format (name )
118
230
119
- local fibers = {}
120
- local report = {errors = {}, count = 0 }
121
- for id = 1 , fiber_count do
122
- local conn_id = id % connection_count + 1
123
- local conn = connections [conn_id ]
124
- local f = fiber .new (insert_customers , conn , id , fiber_count , timeout , report )
125
- f :set_joinable (true )
126
- table.insert (fibers , f )
231
+ if case .prepare ~= nil then
232
+ g .before_test (test_name , case .prepare )
127
233
end
128
234
129
- for i = 1 , fiber_count do
130
- fibers [i ]:join ()
131
- end
235
+ g [test_name ] = function (g )
236
+ local timeout , fiber_count , connection_count
237
+ if g .perf_mode_on then
238
+ timeout = 30
239
+ fiber_count = 200
240
+ connection_count = 10
241
+ else
242
+ timeout = 2
243
+ fiber_count = 5
244
+ connection_count = 2
245
+ end
132
246
133
- log .error (' \n INSERT: requests %d, rps %d, errors %d' ,
134
- report .count , report .count / timeout , # report .errors )
135
- end
247
+ local connections = {}
136
248
137
- g .test_select = function ()
138
- local timeout = 30
139
- local fiber_count = 200
140
- local connection_count = 10
141
- local connections = {}
142
-
143
- local server = g .cluster .main_server
144
- server .net_box :eval ([[ require('crud')]] )
145
- for _ = 1 , connection_count do
146
- local c = net_box :connect (server .net_box_uri , server .net_box_credentials )
147
- assert (c )
148
- table.insert (connections , c )
149
- end
249
+ local server = g .cluster .main_server
150
250
151
- local fibers = {}
152
- local report = {errors = {}, count = 0 }
153
- for id = 1 , fiber_count do
154
- local conn_id = id % connection_count + 1
155
- local conn = connections [conn_id ]
156
- local f = fiber .new (select_customers , conn , id , timeout , report )
157
- f :set_joinable (true )
158
- table.insert (fibers , f )
159
- end
251
+ for _ = 1 , connection_count do
252
+ local c = net_box :connect (server .net_box_uri , server .net_box_credentials )
253
+ assert (c )
254
+ table.insert (connections , c )
255
+ end
160
256
161
- for i = 1 , fiber_count do
162
- fibers [i ]:join ()
163
- end
257
+ local fibers = {}
258
+ local report = {errors = {}, count = 0 }
259
+ for id = 1 , fiber_count do
260
+ local conn_id = id % connection_count + 1
261
+ local conn = connections [conn_id ]
262
+ local f = fiber .new (select_customers , conn , id , timeout , report , case .call )
263
+ f :set_joinable (true )
264
+ table.insert (fibers , f )
265
+ end
266
+
267
+ for i = 1 , fiber_count do
268
+ fibers [i ]:join ()
269
+ end
164
270
165
- log .error (' \n SELECT: requests %d, rps %d, errors %d' ,
166
- report .count , report .count / timeout , # report .errors )
271
+ log .error (' \n %s: requests %d, rps %d, errors %d' ,
272
+ test_name , report .count , report .count / timeout , # report .errors )
273
+ end
167
274
end
0 commit comments