-
Notifications
You must be signed in to change notification settings - Fork 1
/
suite-lib.lua
315 lines (276 loc) · 7.71 KB
/
suite-lib.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
--
-- WARMERS --
--
local FLUSH_AFTER <const> = 50000000
function perf_warm(a)
local count = a.limit
local size = a.vsize
local prefix = a.prefix
local written = 0
local shuffle = a.shuffle
local sleep = a.sleep
local flush_after = FLUSH_AFTER
if a.flush_after then
flush_after = a.flush_after
end
local c = mcs.client_new({})
if c == nil then
plog("LOG", "ERROR", "warmer failed to connect to host")
return
end
if mcs.client_connect(c) == false then
plog("LOG", "ERROR", "warmer failed to connect")
return
end
local numbers = {}
if shuffle then
for i=1,count do
table.insert(numbers, i)
end
-- shuffle
for i=#numbers, 2, -1 do
local j = math.random(i)
numbers[i], numbers[j] = numbers[j], numbers[i]
end
end
for i=1,count do
local num = i
if shuffle then
num = numbers[i]
end
local req = mcs.ms(prefix, num, size, "q")
mcs.client_write(c, req)
written = written + size
if written > flush_after then
mcs.client_flush(c)
written = 0
if sleep then
mcs.sleep_millis(sleep)
end
end
if math.floor(i % (count / 10)) == 0 then
plog("LOG", "INFO", "warming pct", tostring(math.floor(i / count * 100)))
end
end
mcs.client_write(c, "mn\r\n")
mcs.client_flush(c)
local res = mcs.res_new()
-- TODO: bother validating MN? this doesn't fail here.
mcs.client_read(c, res)
end
function perf_warm_cas(a)
local count = a.limit
local size = a.vsize
local prefix = a.prefix
local written = 0
local shuffle = a.shuffle
local sleep = a.sleep
local c = mcs.client_new({})
if c == nil then
plog("LOG", "ERROR", "warmer failed to connect to host")
return
end
if mcs.client_connect(c) == false then
plog("LOG", "ERROR", "warmer failed to connect")
return
end
local numbers = {}
if shuffle then
for i=1,count do
table.insert(numbers, i)
end
-- shuffle
for i=#numbers, 2, -1 do
local j = math.random(i)
numbers[i], numbers[j] = numbers[j], numbers[i]
end
end
local get_res = mcs.res_new()
for i=1,count do
local num = i
if shuffle then
num = numbers[i]
end
local get_req = mcs.mg(prefix, num, "c N30")
mcs.client_write(c, get_req)
mcs.client_flush(c)
mcs.client_read(c, get_res)
local _, cas = mcs.res_flagtoken(get_res, "c")
local set_req = mcs.ms(prefix, num, size, "q C" .. cas)
mcs.client_write(c, set_req)
--mcs.client_flush(c)
if math.floor(i % (count / 10)) == 0 then
plog("LOG", "INFO", "cas warming pct", tostring(math.floor(i / count * 100)))
end
end
mcs.client_write(c, "mn\r\n")
mcs.client_flush(c)
local res = mcs.res_new()
-- TODO: bother validating MN? this doesn't fail here.
mcs.client_read(c, res)
end
--
-- STATS DISPLAY
--
function _stat_sample(a)
local stats = {}
local res = mcs.res_new()
if a.previous_stats == nil then
a.previous_stats = {}
end
local previous_stats = a.previous_stats
while true do
mcs.read(res)
if mcs.res_startswith(res, "END") then
break
end
stats[mcs.res_statname(res)] = mcs.res_stat(res)
end
plog("NEWSTATS", "COUNT")
for _, s in pairs(a["stats"]) do
if previous_stats[s] ~= nil then
local count = stats[s] - previous_stats[s]
plog("STAT", s, count)
end
end
plog("ENDSTATS")
plog("NEWSTATS", "TRACK")
for _, s in pairs(a["track"]) do
if stats[s] ~= nil then
plog("STAT", s, stats[s])
end
end
plog("ENDSTATS")
a.previous_stats = stats
end
function _stat_full(a)
local stats = {}
local res = mcs.res_new()
plog("NEWSTATS", "TRACK")
while true do
mcs.read(res)
if mcs.res_startswith(res, "END") then
break
end
plog("STAT", mcs.res_statname(res), mcs.res_stat(res))
end
plog("END")
end
function proxy_stat_sample(a)
mcs.write("stats proxy\r\n")
mcs.flush()
_stat_sample(a)
end
function proxyfuncs_stat_sample(a)
mcs.write("stats proxyfuncs\r\n")
mcs.flush()
_stat_full(a)
end
function stat_sample(a)
mcs.write("stats\r\n")
mcs.flush()
_stat_sample(a)
end
-- uses client mode so we can exit a shredder run when complete.
function full_stats(a)
local subcmd = a.sub
local c = mcs.client_new({})
if c == nil then
plog("LOG", "ERROR", "stats dumper failed to connect")
return
end
if mcs.client_connect(c) == false then
plog("LOG", "ERROR", "stats dumper failed to connect")
return
end
if subcmd ~= nil then
mcs.client_write(c, "stats " .. subcmd .. "\r\n")
else
mcs.client_write(c, "stats\r\n")
end
mcs.client_flush(c)
local res = mcs.res_new()
plog("FULLSTATS")
while true do
mcs.client_read(c, res)
if mcs.res_startswith(res, "END") then
break
end
plog("STAT", mcs.res_statname(res), mcs.res_stat(res))
end
plog("ENDSTATS")
end
--
-- STATISTICS --
--
-- we create some small canary values for this timer to fetch so tests with
-- bandwidth limits, large values, etc, aren't as skewed.
-- this latency sampler isn't meant to be for super detailed performance, but
-- to help characterize some performance and failures.
function timer_metaget(a)
local prefix = a.prefix .. "canary"
local req = mcs.mg_factory(prefix, "v")
local res = mcs.res_new()
return function()
local num = math.random(50)
mcs.write_factory(req, num)
mcs.flush()
mcs.read(res)
local status, elapsed = mcs.match(req, res)
-- TODO: split hit vs miss timing?
local bucket = math.floor(math.log(elapsed, 10) + 1)
-- sub-ms are bucketed logarithmically
if bucket > 5 then
timer_bounds = timer_bounds + 1
elseif bucket > 3 then
-- TODO: kill granularity but still bucket above 10ms
bucket = math.floor(elapsed / 1000)
timer_mshist[bucket] = timer_mshist[bucket] + 1
else
timer_hist[bucket] = timer_hist[bucket] + 1
end
--print("timer sample:", elapsed, bucket)
if mcs.res_startswith(res, "EN") then
local set = mcs.ms(prefix, num, 10)
mcs.write(set)
mcs.flush()
mcs.read(res)
-- TODO: this shouldn't fail, but we can still check the response.
end
end
end
-- uses globals to share data with timer funcs.
function timer_display(a)
timer_hist = {}
timer_mshist = {}
timer_bounds = 0
for i=1,3 do
table.insert(timer_hist, 0)
end
for i=1,100 do
table.insert(timer_mshist, 0)
end
-- TODO: use out func to print all at once.
return function()
plog("TIMER")
plog("TIME", "1us", timer_hist[1])
plog("TIME", "10us", timer_hist[2])
plog("TIME", "100us", timer_hist[3])
for i=1,100 do
if timer_mshist[i] > 0 then
plog("TIME", i .. "ms", timer_mshist[i])
end
end
if timer_bounds ~= 0 then
plog("TIME", "100ms+:", timer_bounds)
end
plog("ENDTIMER")
for i=1,3 do
timer_hist[i] = 0
end
for i=1,100 do
timer_mshist[i] = 0
end
timer_bounds = 0
end
end