This repository was archived by the owner on Jan 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanner_test02.cpp
More file actions
475 lines (418 loc) · 15.1 KB
/
planner_test02.cpp
File metadata and controls
475 lines (418 loc) · 15.1 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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/*****************************************************************************\
* Copyright (c) 2014 Lawrence Livermore National Security, LLC. Produced at
* the Lawrence Livermore National Laboratory (cf, AUTHORS, DISCLAIMER.LLNS).
* LLNL-CODE-658032 All rights reserved.
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the license, or (at your option)
* any later version.
*
* Flux is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* See also: http://www.gnu.org/licenses/
\*****************************************************************************/
#include <iostream>
#include <sstream>
#include <cstdint>
#include <cstring>
#include <cerrno>
#include <map>
#include <vector>
#include <sys/time.h>
#include "tap.h"
#include "planner.h"
const int million = 1048576;
struct perf_t {
planner_t *planner;
int64_t span_count;
std::string label;
std::string interval;
double elapse;
};
std::map<std::string, std::vector<perf_t *> > exp_data;
static void to_stream (int64_t base_time, uint64_t duration, const uint64_t *cnts,
const char **types, size_t len, std::stringstream &ss)
{
if (base_time != -1)
ss << "B(" << base_time << "):";
ss << "D(" << duration << "):" << "R(<";
for (unsigned int i = 0; i < len; ++i)
ss << types[i] << "(" << cnts[i] << ")";
ss << ">)";
}
static double elapse_time (timeval &st, timeval &et)
{
double ts1 = (double) st.tv_sec + (double) st.tv_usec/1000000.0f;
double ts2 = (double) et.tv_sec + (double) et.tv_usec/1000000.0f;
return ts2 - ts1;
}
int report (std::string experiment)
{
int i, start;
std::cout << "Experiment: " << experiment << std::endl;
std::cout << "Overlap-Factor";
size_t sz = exp_data.begin ()->second.size ();
start = million >> (sz - 1);
std::cout << "start: " << start;
for (i = start; i < (million + 1) ; i = i << 1) {
std::cout << ", " << i;
}
std::cout << std::endl;
for (auto &kv : exp_data) {
std::cout << kv.first;
for (auto &perf : kv.second) {
std::cout << ", " << perf->elapse;
}
for (auto &perf : kv.second) {
delete perf;
}
kv.second.clear ();
std::cout << std::endl;
}
if (!exp_data.empty ())
exp_data.clear ();
return 0;
}
perf_t *create_perf (planner_t *ctx, int64_t count, int overlap, double elapse, int64_t end_time)
{
std::stringstream ss;
perf_t *perf = new perf_t ();
perf->planner = ctx;
perf->span_count = count;
ss << "Overlaps(" << overlap << ")";
perf->label = ss.str ();
perf->elapse = elapse;
ss.str () = "";
ss << "[0, " << end_time << ")";
perf->interval = ss.str ();
return perf;
}
int test_query_perf_1d ()
{
int64_t i;
int end = 0, j, rc;
int64_t at=0, span=0, avail=0;
size_t len = 1;
bool bo = false;
struct timeval st, et;
const uint64_t resource_totals[] = {10};
const char *resource_types[] = {"core"};
std::vector<uint64_t> count_vector;
std::vector<int64_t> query_times;
planner_t *ctx = NULL;
std::stringstream ss;
count_vector.push_back (10);
count_vector.push_back (5);
count_vector.push_back (2);
count_vector.push_back (1);
errno = 0;
to_stream (0, INT64_MAX, resource_totals,
(const char **)resource_types, len, ss);
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
ok ((ctx && !errno), "new with (%s)", ss.str ().c_str ());
ss.str ("");
for (auto count : count_vector) {
for (end = 2048; end < (2*million + 1); end = end << 1) {
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
int overlap_factor = resource_totals[0]/count;
std::vector<int64_t> spans;
for (i = 0; i < end; ++i) {
at = (int64_t)(i/overlap_factor * 1000);
span = planner_add_span (ctx, at, 1000, (const uint64_t *)&count, len);
spans.push_back (span);
bo = (bo || span == -1);
}
for (i = 0; i < end; i += 2) {
// delete 1/2 of the spans
rc = planner_rem_span (ctx, (int64_t)spans[i]);
bo = (bo || rc == -1);
}
//fix the seed for reproducibility
srandom (i);
for (j = 0; j < 1024; ++j) {
double norm = (double)random ()/(double)(RAND_MAX);
double adjusted = norm * (double)(at + 1000);
int64_t query_time = (int64_t)adjusted;
query_times.push_back (query_time);
}
gettimeofday (&st, NULL);
for (j = 0; j < 1024; ++j) {
avail = planner_avail_resources_at (ctx, query_times[j], 0);
bo = (bo || avail == -1);
}
gettimeofday (&et, NULL);
// Generate a data point
perf_t *p = create_perf (ctx, planner_span_size (ctx), overlap_factor,
elapse_time (st, et), at + 1000);
ss.str ("");
ss << "Overlap(" << overlap_factor << ")";
exp_data[ss.str ()].push_back (p);
query_times.clear ();
}
}
ok (!bo && !errno, "time-based query performance: 1 resource type");
printf ("%s\n", std::strerror (errno));
return 0;
}
int test_avail_time_perf ()
{
int64_t i;
int end = 0, j, rc;
int64_t at=0, span=0, t=0;
size_t len = 1;
bool bo = false;
struct timeval st, et;
const uint64_t resource_totals[] = {10};
const char *resource_types[] = {"core"};
std::vector<uint64_t> count_vector;
std::vector<int64_t> query_times;
planner_t *ctx = NULL;
std::stringstream ss;
count_vector.push_back (10);
count_vector.push_back (5);
count_vector.push_back (2);
count_vector.push_back (1);
errno = 0;
to_stream (0, INT64_MAX, resource_totals,
(const char **)resource_types, len, ss);
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
ok ((ctx && !errno), "new with (%s)", ss.str ().c_str ());
ss.str ("");
for (auto count : count_vector) {
for (end = 32768; end < (2*million + 1); end = end << 1) {
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
int overlap_factor = resource_totals[0]/count;
std::vector<int64_t> spans;
for (i = 0; i < end; ++i) {
at = (int64_t)(i/overlap_factor * 1000);
span = planner_add_span (ctx, at, 1000, (const uint64_t *)&count, len);
spans.push_back (span);
bo = (bo || span == -1);
}
for (i = 0; i < end; i += 2) {
// delete 1/2 of the spans
rc = planner_rem_span (ctx, (int64_t)spans[i]);
bo = (bo || rc == -1);
}
j = 0;
gettimeofday (&st, NULL);
t = planner_avail_time_first (ctx, 0+1, 1, (const uint64_t *)&count, len);
bo = (bo || t == -1);
while (j < 1024 && t != -1) {
t = planner_avail_time_next (ctx);
bo = (bo || t == -1);
//if (bo)
// std::cout << end << ": " << count << ":" << j << ":" << t << std::endl;
j++;
}
gettimeofday (&et, NULL);
// Generate a data point
perf_t *p = create_perf (ctx, planner_span_size (ctx), overlap_factor,
elapse_time (st, et), at + 1000);
ss.str ("");
ss << "Overlap(" << overlap_factor << ")";
exp_data[ss.str ()].push_back (p);
query_times.clear ();
}
}
ok (!bo && !errno, "resource-based query performance: 1 resource type");
printf ("%s\n", std::strerror (errno));
return 0;
}
int test_rem_perf_1d ()
{
int end = 0, i, rc;
int64_t at, span;
size_t len = 1;
bool bo = false;
struct timeval st, et;
const uint64_t resource_totals[] = {10};
const char *resource_types[] = {"core"};
std::vector<uint64_t> count_vector;
std::vector<int64_t> query_times;
planner_t *ctx = NULL;
std::stringstream ss;
count_vector.push_back (10);
count_vector.push_back (5);
count_vector.push_back (2);
count_vector.push_back (1);
errno = 0;
to_stream (0, INT64_MAX, resource_totals,
(const char **)resource_types, len, ss);
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
ok ((ctx && !errno), "new with (%s)", ss.str ().c_str ());
ss.str ("");
for (auto count : count_vector) {
for (end = 1024; end < (million + 1); end = end << 1) {
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
int overlap_factor = resource_totals[0]/count;
std::vector<int64_t> spans;
for (i = 0; i < end; ++i) {
at = i/overlap_factor * 1000;
span = planner_add_span (ctx, at, 1000, (const uint64_t *)&count, 1);
spans.push_back (span);
bo = (bo || span == -1);
}
int stride = i / 1024;
gettimeofday (&st, NULL);
for (i = 0; i < end; i += stride) {
// delete 1024 spans spread equally across the interval
rc = planner_rem_span (ctx, spans[i]);
bo = (bo || rc == -1);
}
gettimeofday (&et, NULL);
// Generate a data point //TODO
perf_t *p = create_perf (ctx, end, overlap_factor,
elapse_time (st, et), at + 1000);
ss.str ("");
ss << "Overlap(" << overlap_factor << ")";
exp_data[ss.str ()].push_back (p);
}
}
ok (!bo && !errno, "remove performance: 1 resource type");
return 0;
}
int test_add_perf_1d ()
{
int end = 0, i;
int64_t at, span;
size_t len = 1;
bool bo = false;
struct timeval st, et;
const uint64_t resource_totals[] = {10};
const char *resource_types[] = {"core"};
std::vector<uint64_t> count_vector;
planner_t *ctx = NULL;
std::stringstream ss;
count_vector.push_back (10);
count_vector.push_back (5);
count_vector.push_back (2);
count_vector.push_back (1);
errno = 0;
to_stream (0, INT64_MAX, resource_totals,
(const char **)resource_types, len, ss);
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
ok ((ctx && !errno), "new with (%s)", ss.str ().c_str ());
ss.str ("");
for (auto count : count_vector) {
for (end = 1024; end < (million + 1); end = end << 1) {
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
int overlap_factor = resource_totals[0]/count;
gettimeofday (&st, NULL);
for (i = 0; i < end; ++i) {
at = i/overlap_factor * 1000;
span = planner_add_span (ctx, at, 1000, (const uint64_t *)&count, 1);
bo = (bo || span == -1);
}
gettimeofday (&et, NULL);
// Generate a data point
perf_t *p = create_perf (ctx, planner_span_size (ctx), overlap_factor,
elapse_time (st, et), at + 1000);
ss.str ("");
ss << "Overlap(" << overlap_factor << ")";
exp_data[ss.str ()].push_back (p);
}
}
ok (!bo && !errno, "add performance: 1 resource type");
return 0;
}
int test_add_perf_5d ()
{
int end = 0, i;
int64_t at, span;
size_t len = 5;
bool bo = false;
struct timeval st, et;
const uint64_t resource_totals[] = {10, 100, 1000, 10000, 100000};
const char *resource_types[] = {"cluster", "rack", "node", "socket", "core"};
std::vector<std::vector<uint64_t> > count_vv;
planner_t *ctx = NULL;
std::stringstream ss;
count_vv.push_back (std::vector<uint64_t>());
count_vv.push_back (std::vector<uint64_t>());
count_vv.push_back (std::vector<uint64_t>());
count_vv.push_back (std::vector<uint64_t>());
for (i = 0; i < 5; ++i) {
count_vv[0].push_back (resource_totals[i]);
count_vv[1].push_back (resource_totals[i]/2);
count_vv[2].push_back (resource_totals[i]/5);
count_vv[3].push_back (resource_totals[i]/10);
}
errno = 0;
to_stream (0, INT64_MAX, resource_totals,
(const char **)resource_types, len, ss);
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
ok ((ctx && !errno), "new with (%s)", ss.str ().c_str ());
ss.str ("");
for (auto &count_vector : count_vv) {
for (end = 1024; end < (million + 1); end = end<<1) {
ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len);
int overlap_factor = resource_totals[0]/count_vector[0];
gettimeofday (&st, NULL);
for (i = 0; i < end; ++i) {
at = i/overlap_factor * 1000;
span = planner_add_span (ctx, at, 1000,
(const uint64_t *)&(count_vector[0]), 5);
bo = (bo || span == -1);
}
gettimeofday (&et, NULL);
// Generate a data point
perf_t *p = create_perf (ctx, planner_span_size (ctx), overlap_factor,
elapse_time (st, et), at + 1000);
ss.str ("");
ss << "Overlap(" << overlap_factor << ")";
exp_data[ss.str ()].push_back (p);
}
}
ok (!bo && !errno, "add performance: 5 resource types");
return 0;
}
int test_add_performance ()
{
test_add_perf_1d ();
return report ("Planner Add Performance: 1D");
}
int test_add_performance2 ()
{
test_add_perf_5d ();
return report ("Planner Add Performance: 5D");
}
int test_query_performance ()
{
test_query_perf_1d ();
return report ("Planner Time-Based Query Performance");
}
int test_avail_time_performance ()
{
test_avail_time_perf ();
return report ("Planner Resource_Based Query Performance");
}
int test_rem_performance ()
{
test_rem_perf_1d ();
return report ("Planner Remove Performance");
}
int main (int argc, char *argv[])
{
plan (10);
test_add_performance ();
test_add_performance2 ();
test_query_performance ();
test_avail_time_performance ();
test_rem_performance ();
done_testing ();
return EXIT_SUCCESS;
}
/*
* vi: ts=4 sw=4 expandtab
*/