forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_DataRelayer.cxx
More file actions
357 lines (295 loc) · 13 KB
/
benchmark_DataRelayer.cxx
File metadata and controls
357 lines (295 loc) · 13 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <benchmark/benchmark.h>
#include "Headers/DataHeader.h"
#include "Headers/Stack.h"
#include "Framework/CompletionPolicyHelpers.h"
#include "Framework/DataRelayer.h"
#include "Framework/DataProcessingHeader.h"
#include <Monitoring/Monitoring.h>
#include <fairmq/TransportFactory.h>
#include <cstring>
#include <vector>
using Monitoring = o2::monitoring::Monitoring;
using namespace o2::framework;
using DataHeader = o2::header::DataHeader;
using Stack = o2::header::Stack;
using RecordAction = o2::framework::DataRelayer::RecordAction;
// a simple benchmark of the contribution of the pure message creation
// this was important when the benchmarks below included the message
// creation inside the benchmark loop, its somewhat obsolete now but
// we keep it for reference
static void BM_RelayMessageCreation(benchmark::State& state)
{
DataHeader dh;
dh.dataDescription = "CLUSTERS";
dh.dataOrigin = "TPC";
dh.subSpecification = 0;
DataProcessingHeader dph{0, 1};
Stack stack{dh, dph};
auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
for (auto _ : state) {
fair::mq::MessagePtr header = transport->CreateMessage(stack.size());
fair::mq::MessagePtr payload = transport->CreateMessage(1000);
memcpy(header->GetData(), stack.data(), stack.size());
}
}
BENCHMARK(BM_RelayMessageCreation);
// A simple test where an input is provided
// and the subsequent InputRecord is immediately requested.
static void BM_RelaySingleSlot(benchmark::State& state)
{
Monitoring metrics;
InputSpec spec{"clusters", "TPC", "CLUSTERS"};
std::vector<InputRoute> inputs = {
InputRoute{spec, 0, "Fake", 0}};
std::vector<ForwardRoute> forwards;
std::vector<InputChannelInfo> infos{1};
TimesliceIndex index{1, infos};
auto policy = CompletionPolicyHelpers::consumeWhenAny();
ServiceRegistry registry;
DataRelayer relayer(policy, inputs, index, {registry}, -1);
relayer.setPipelineLength(4);
// Let's create a dummy O2 Message with two headers in the stack:
// - DataHeader matching the one provided in the input
DataHeader dh;
dh.dataDescription = "CLUSTERS";
dh.dataOrigin = "TPC";
dh.subSpecification = 0;
DataProcessingHeader dph{0, 1};
Stack stack{dh, dph};
auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
// we are creating the inflight messages once outside the benchmark
// loop and make sure that they are moved back to the original vector
// when processed by the relayer
std::vector<fair::mq::MessagePtr> inflightMessages;
inflightMessages.emplace_back(transport->CreateMessage(stack.size()));
inflightMessages.emplace_back(transport->CreateMessage(1000));
memcpy(inflightMessages[0]->GetData(), stack.data(), stack.size());
DataRelayer::InputInfo fakeInfo{0, inflightMessages.size(), DataRelayer::InputType::Data, {ChannelIndex::INVALID}};
for (auto _ : state) {
relayer.relay(inflightMessages[0]->GetData(), inflightMessages.data(), fakeInfo, inflightMessages.size());
std::vector<RecordAction> ready;
relayer.getReadyToProcess(ready);
assert(ready.size() == 1);
assert(ready[0].slot.index == 0);
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
assert(result.size() == 1);
assert((result.at(0).messages | count_parts{}) == 1);
inflightMessages = std::move(result[0].messages);
}
}
BENCHMARK(BM_RelaySingleSlot);
// This one will simulate a single input.
static void BM_RelayMultipleSlots(benchmark::State& state)
{
Monitoring metrics;
InputSpec spec{"clusters", "TPC", "CLUSTERS"};
std::vector<InputRoute> inputs = {
InputRoute{spec, 0, "Fake", 0}};
std::vector<ForwardRoute> forwards;
std::vector<InputChannelInfo> infos{1};
TimesliceIndex index{1, infos};
auto policy = CompletionPolicyHelpers::consumeWhenAny();
ServiceRegistry registry;
DataRelayer relayer(policy, inputs, index, {registry}, -1);
relayer.setPipelineLength(4);
// Let's create a dummy O2 Message with two headers in the stack:
// - DataHeader matching the one provided in the input
DataHeader dh;
dh.dataDescription = "CLUSTERS";
dh.dataOrigin = "TPC";
dh.subSpecification = 0;
auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
size_t timeslice = 0;
DataProcessingHeader dph{timeslice, 1};
Stack placeholder{dh, dph};
// we are creating the inflight messages once outside the benchmark
// loop and make sure that they are moved back to the original vector
// when processed by the relayer
std::vector<fair::mq::MessagePtr> inflightMessages;
inflightMessages.emplace_back(transport->CreateMessage(placeholder.size()));
inflightMessages.emplace_back(transport->CreateMessage(1000));
for (auto _ : state) {
Stack stack{dh, DataProcessingHeader{timeslice++, 1}};
memcpy(inflightMessages[0]->GetData(), stack.data(), stack.size());
DataRelayer::InputInfo fakeInfo{0, inflightMessages.size(), DataRelayer::InputType::Data, {ChannelIndex::INVALID}};
relayer.relay(inflightMessages[0]->GetData(), inflightMessages.data(), fakeInfo, inflightMessages.size());
std::vector<RecordAction> ready;
relayer.getReadyToProcess(ready);
assert(ready.size() == 1);
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
assert(result.size() == 1);
assert((result.at(0).messages | count_parts{}) == 1);
inflightMessages = std::move(result[0].messages);
}
}
BENCHMARK(BM_RelayMultipleSlots);
/// In this case we have a record with two entries
static void BM_RelayMultipleRoutes(benchmark::State& state)
{
Monitoring metrics;
InputSpec spec1{"clusters", "TPC", "CLUSTERS"};
InputSpec spec2{"tracks", "TPC", "TRACKS"};
std::vector<InputRoute> inputs = {
InputRoute{spec1, 0, "Fake1", 0},
InputRoute{spec2, 1, "Fake2", 0}};
std::vector<ForwardRoute> forwards;
std::vector<InputChannelInfo> infos{1};
TimesliceIndex index{1, infos};
auto policy = CompletionPolicyHelpers::consumeWhenAny();
ServiceRegistry registry;
DataRelayer relayer(policy, inputs, index, {registry}, -1);
relayer.setPipelineLength(4);
// Let's create a dummy O2 Message with two headers in the stack:
// - DataHeader matching the one provided in the input
DataHeader dh1;
dh1.dataDescription = "CLUSTERS";
dh1.dataOrigin = "TPC";
dh1.subSpecification = 0;
DataHeader dh2;
dh2.dataDescription = "TRACKS";
dh2.dataOrigin = "TPC";
dh2.subSpecification = 0;
auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
size_t timeslice = 0;
DataProcessingHeader dph1{timeslice, 1};
Stack stack1{dh1, dph1};
std::vector<fair::mq::MessagePtr> inflightMessages;
inflightMessages.emplace_back(transport->CreateMessage(stack1.size()));
inflightMessages.emplace_back(transport->CreateMessage(1000));
memcpy(inflightMessages[0]->GetData(), stack1.data(), stack1.size());
DataProcessingHeader dph2{timeslice, 1};
Stack stack2{dh2, dph2};
inflightMessages.emplace_back(transport->CreateMessage(stack2.size()));
inflightMessages.emplace_back(transport->CreateMessage(1000));
memcpy(inflightMessages[2]->GetData(), stack2.data(), stack2.size());
for (auto _ : state) {
DataRelayer::InputInfo fakeInfo{0, inflightMessages.size(), DataRelayer::InputType::Data, {ChannelIndex::INVALID}};
relayer.relay(inflightMessages[0]->GetData(), &inflightMessages[0], fakeInfo, 2);
std::vector<RecordAction> ready;
relayer.getReadyToProcess(ready);
assert(ready.size() == 1);
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
DataRelayer::InputInfo fakeInfo2{0, inflightMessages.size(), DataRelayer::InputType::Data, {ChannelIndex::INVALID}};
relayer.relay(inflightMessages[2]->GetData(), &inflightMessages[2], fakeInfo2, 2);
ready.clear();
relayer.getReadyToProcess(ready);
assert(ready.size() == 1);
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
assert(result.size() == 2);
assert((result.at(0).messages | count_parts{}) == 1);
assert((result.at(1).messages | count_parts{}) == 1);
inflightMessages = std::move(result[0].messages);
inflightMessages.emplace_back(std::move(result[1].messages[0]));
inflightMessages.emplace_back(std::move(result[1].messages[1]));
}
}
BENCHMARK(BM_RelayMultipleRoutes);
/// In this case we have a record with two entries
static void BM_RelaySplitParts(benchmark::State& state)
{
Monitoring metrics;
InputSpec spec1{"clusters", "TPC", "CLUSTERS"};
std::vector<InputRoute> inputs = {
InputRoute{spec1, 0, "Fake1", 0},
};
std::vector<ForwardRoute> forwards;
std::vector<InputChannelInfo> infos{1};
TimesliceIndex index{1, infos};
auto policy = CompletionPolicyHelpers::consumeWhenAny();
ServiceRegistry registry;
DataRelayer relayer(policy, inputs, index, {registry}, -1);
relayer.setPipelineLength(4);
// Let's create a dummy O2 Message with two headers in the stack:
// - DataHeader matching the one provided in the input
DataHeader dh;
dh.dataDescription = "CLUSTERS";
dh.dataOrigin = "TPC";
dh.subSpecification = 0;
dh.payloadSize = 100;
auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
size_t timeslice = 0;
const int nSplitParts = state.range(0);
std::vector<std::unique_ptr<fair::mq::Message>> inflightMessages;
inflightMessages.reserve(2 * nSplitParts);
for (size_t i = 0; i < nSplitParts; ++i) {
DataProcessingHeader dph{timeslice, 1};
dh.splitPayloadIndex = i;
dh.splitPayloadParts = nSplitParts;
Stack stack{dh, dph};
fair::mq::MessagePtr header = transport->CreateMessage(stack.size());
fair::mq::MessagePtr payload = transport->CreateMessage(dh.payloadSize);
memcpy(header->GetData(), stack.data(), stack.size());
inflightMessages.emplace_back(std::move(header));
inflightMessages.emplace_back(std::move(payload));
}
DataRelayer::InputInfo fakeInfo{0, inflightMessages.size(), DataRelayer::InputType::Data, {ChannelIndex::INVALID}};
for (auto _ : state) {
relayer.relay(inflightMessages[0]->GetData(), inflightMessages.data(), fakeInfo, inflightMessages.size());
std::vector<RecordAction> ready;
relayer.getReadyToProcess(ready);
assert(ready.size() == 1);
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
inflightMessages = std::move(relayer.consumeAllInputsForTimeslice(ready[0].slot)[0].messages);
}
}
BENCHMARK(BM_RelaySplitParts)->Arg(10)->Arg(100)->Arg(1000);
static void BM_RelayMultiplePayloads(benchmark::State& state)
{
Monitoring metrics;
InputSpec spec1{"clusters", "TPC", "CLUSTERS"};
std::vector<InputRoute> inputs = {
InputRoute{spec1, 0, "Fake1", 0},
};
std::vector<ForwardRoute> forwards;
std::vector<InputChannelInfo> infos{1};
TimesliceIndex index{1, infos};
auto policy = CompletionPolicyHelpers::consumeWhenAny();
ServiceRegistry registry;
DataRelayer relayer(policy, inputs, index, {registry}, -1);
relayer.setPipelineLength(4);
// DataHeader matching the one provided in the input
DataHeader dh;
dh.dataDescription = "CLUSTERS";
dh.dataOrigin = "TPC";
dh.subSpecification = 0;
dh.payloadSize = 100;
auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
size_t timeslice = 0;
const int nPayloads = state.range(0);
std::vector<std::unique_ptr<fair::mq::Message>> inflightMessages;
inflightMessages.reserve(nPayloads + 1);
DataProcessingHeader dph{timeslice, 1};
dh.splitPayloadIndex = nPayloads;
dh.splitPayloadParts = nPayloads;
Stack stack{dh, dph};
fair::mq::MessagePtr header = transport->CreateMessage(stack.size());
memcpy(header->GetData(), stack.data(), stack.size());
inflightMessages.emplace_back(std::move(header));
for (size_t i = 0; i < nPayloads; ++i) {
inflightMessages.emplace_back(transport->CreateMessage(dh.payloadSize));
}
DataRelayer::InputInfo fakeInfo{0, inflightMessages.size(), DataRelayer::InputType::Data, {ChannelIndex::INVALID}};
for (auto _ : state) {
relayer.relay(inflightMessages[0]->GetData(), inflightMessages.data(), fakeInfo, inflightMessages.size(), nPayloads);
std::vector<RecordAction> ready;
relayer.getReadyToProcess(ready);
assert(ready.size() == 1);
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
inflightMessages = std::move(relayer.consumeAllInputsForTimeslice(ready[0].slot)[0].messages);
}
}
BENCHMARK(BM_RelayMultiplePayloads)->Arg(10)->Arg(100)->Arg(1000);
BENCHMARK_MAIN();