-
Notifications
You must be signed in to change notification settings - Fork 1
/
suite-performance-lib.lua
286 lines (244 loc) · 7.67 KB
/
suite-performance-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
--
-- PERFORMANCE RUNNERS --
--
local PERFRUN_HIST <const> = 1
local PERFRUN_MSHIST <const> = 2
local PERFRUN_OOB <const> = 3
perfrun_stats = {}
-- run one of these on each thread issuing performance tests. gathers the time
-- history once per second and ships it for summarization.
function perfrun_stats_out()
local t = {"===start==="}
for cmd, stats in pairs(perfrun_stats) do
table.insert(t, cmd)
local hist = stats[PERFRUN_HIST]
table.insert(t, table.concat(hist, ","))
local mshist = stats[PERFRUN_MSHIST]
table.insert(t, table.concat(mshist, ","))
table.insert(t, stats[PERFRUN_OOB])
end
if #t == 1 then
return -- nothing to send right now.
end
table.insert(t, "===end===")
mcs.out(t)
-- TODO: zero out the stats instead of wipe them to cut memory churn
-- slightly.
perfrun_stats = {}
end
-- run on separate stats thread. waits for data from test runner threads,
-- summarizes and prints.
function perfrun_stats_gather(a)
local tcount = 0
local lstats = {}
-- TODO: note thread count.
while true do
mcs.out_wait()
local rline = mcs.out_readline()
if rline ~= "===start===" then
error("expecting startline, got: " .. rline)
end
while true do
-- first line is the command bucket.
rline = mcs.out_readline()
if rline == "===end===" then
break
end
if lstats[rline] == nil then
lstats[rline] = perfrun_init_bucket_cmd()
end
local s = lstats[rline]
-- the next line is us histogram
-- the line after that is ms chart
-- final line os OOB count
rline = mcs.out_readline()
local i = 1
for num in string.gmatch(rline, '([^,]+)') do
s[PERFRUN_HIST][i] = s[PERFRUN_HIST][i] + tonumber(num)
i = i + 1
end
rline = mcs.out_readline()
i = 1
for num in string.gmatch(rline, '([^,]+)') do
s[PERFRUN_MSHIST][i] = s[PERFRUN_MSHIST][i] + tonumber(num)
i = i + 1
end
rline = mcs.out_readline()
s[PERFRUN_OOB] = s[PERFRUN_OOB] + tonumber(rline)
end
tcount = tcount + 1
if tcount == a.threads then
-- seen all threads, dump data.
tcount = 0
for cmd, s in pairs(lstats) do
local timer_hist = s[PERFRUN_HIST]
local timer_mshist = s[PERFRUN_MSHIST]
plog("TIMER", cmd)
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 s[PERFRUN_OOB] ~= 0 then
plog("TIME", "100ms+:", s[PERFRUN_OOB])
end
plog("ENDTIMER")
end
-- reset local stats cache.
lstats = {}
end
end
end
-- TODO: maybe use an add_custom to clear the bucket once, so runners can
-- cache the global reference for a tiny speedup?
function perfrun_init()
perfrun_stats = {}
end
function perfrun_init_bucket_cmd()
local stats = { {}, {}, 0}
-- seed this command bucket.
for i=1,3 do
table.insert(stats[PERFRUN_HIST], 0)
end
for i=1,100 do
table.insert(stats[PERFRUN_MSHIST], 0)
end
return stats
end
function perfrun_bucket(cmd, time)
local stats = perfrun_stats[cmd]
if stats == nil then
stats = perfrun_init_bucket_cmd()
perfrun_stats[cmd] = stats
end
local bucket = math.floor(math.log(time, 10) + 1)
if bucket > 5 then
stats[PERFRUN_OOB] = stats[PERFRUN_OOB] + 1
elseif bucket > 3 then
-- per ms granulairty
bucket = math.floor(time / 1000)
stats[PERFRUN_MSHIST][bucket] = stats[PERFRUN_MSHIST][bucket] + 1
else
-- histogram for sub-ms
stats[PERFRUN_HIST][bucket] = stats[PERFRUN_HIST][bucket] + 1
end
end
function perfrun_metaget(a)
local total_keys = a.limit
local pfx = "perf"
if a.prefix then
pfx = a.prefix
end
local res = mcs.res_new()
local req = mcs.mg_factory(pfx, "v")
-- NOTE: this ends up resetting the global values a bunch of times, but we
-- need to ensure we do it once to clear any data from a previous run.
-- All of the inits run before any actual test code so this is fine.
perfrun_init()
return function()
local num = math.random(total_keys)
mcs.write_factory(req, num)
mcs.flush()
mcs.read(res)
local status, elapsed = mcs.match(req, res)
if not status then
print("mismatched response: " .. num .. " GOT: " .. mcs.resline(res))
end
perfrun_bucket("mg", elapsed)
end
end
function perfrun_metaget_pipe(a)
local total_keys = a.limit
local pipes = a.pipes
local reqfacs = {}
local results = {}
local pfx = "perf"
if a.prefix then
pfx = a.prefix
end
for i=1,pipes do
table.insert(results, mcs.res_new())
table.insert(reqfacs, mcs.mg_factory(pfx, "v"))
end
perfrun_init()
return function()
for i=1,pipes do
local num = math.random(total_keys)
mcs.write_factory(reqfacs[i], num)
end
mcs.flush()
for i=1,pipes do
local res = results[i]
mcs.read(res)
local status, elapsed = mcs.match(reqfacs[i], res)
if not status then
print("mismatched response: " .. num .. " GOT: " .. mcs.resline(res))
end
perfrun_bucket("mg", elapsed)
end
end
end
function perfrun_metaset(a)
local total_keys = a.limit
local size = a.vsize
local pfx = "perf"
if a.prefix then
pfx = a.prefix
end
local flags = ""
if a.flags then
flags = a.flags
end
local res = mcs.res_new()
local req = mcs.ms_factory(pfx, flags)
perfrun_init()
return function()
local num = math.random(total_keys)
mcs.write_factory(req, num, size)
mcs.flush()
mcs.read(res)
local status, elapsed = mcs.match(req, res)
if not status then
print("mismatched response: " .. num .. " GOT: " .. mcs.resline(res))
end
perfrun_bucket("ms", elapsed)
end
end
function perfrun_metacasset(a)
local total_keys = a.limit
local size = a.vsize
local pfx = "perf"
if a.prefix then
pfx = a.prefix
end
local res = mcs.res_new()
--local req = mcs.ms_factory(pfx, "")
local get_req = mcs.mg_factory(pfx, "c N30")
local get_res = mcs.res_new()
perfrun_init()
return function()
local num = math.random(total_keys)
mcs.write_factory(get_req, num)
mcs.flush()
mcs.read(get_res)
local has_cas, cas = mcs.res_flagtoken(get_res, "c")
-- TODO: pass c -> C to the factory?
-- Factory too simple to do it, have to do the same code as warmer.
local set_req = mcs.ms(pfx, num, size, "C" .. cas)
--mcs.write_factory(req, num, size)
mcs.write(set_req)
mcs.flush()
mcs.read(res)
local status, elapsed = mcs.match(set_req, res)
if not status then
print("mismatched response: " .. num .. " GOT: " .. mcs.resline(res))
end
perfrun_bucket("ms", elapsed)
end
end
--
-- END PERFORMANCE RUNNERS
--