-
Notifications
You must be signed in to change notification settings - Fork 1
/
emu_runner.cc
653 lines (553 loc) · 26.2 KB
/
emu_runner.cc
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/*
* Created on: May 13, 2019
* Author: Subhadeep, Papon
*/
#include <sstream>
#include <iostream>
#include <cstdio>
#include <sys/time.h>
#include <cmath>
#include <unistd.h>
#include <assert.h>
#include <fstream>
#include <stdlib.h>
#include <cstdlib>
#include <iomanip>
#include "args.hxx"
#include "emu_environment.h"
#include "tree_builder.h"
#include "workload_executor.h"
#include "workload_generator.h"
#include "query_runner.h"
using namespace std;
using namespace tree_builder;
using namespace workload_exec;
/*
* DECLARATIONS
*/
int Query::delete_key;
int Query::range_start_key;
int Query::range_end_key;
int Query::sec_range_start_key;
int Query::sec_range_end_key;
int Query::iterations_point_query;
//long inserts(EmuEnv* _env);
int parse_arguments2(int argc, char *argvx[], EmuEnv* _env);
void printEmulationOutput(EmuEnv* _env);
void calculateDeleteTileSize(EmuEnv* _env);
float curr_selectivity;
float QueryDrivenCompactionSelectivity;
int insert_time;
//int run_workload(read, pread, rread, write, update, delete, skew, others);
int runWorkload(EmuEnv* _env);
inline void showProgress(const uint32_t &workload_size, const uint32_t &counter) {
// std::cout << "counter = " << counter << std::endl;
if (counter / (workload_size/100) >= 1) {
for (int i = 0; i<104; i++){
std::cout << "\b";
fflush(stdout);
}
}
for (int i = 0; i<counter / (workload_size/100); i++){
std::cout << "=" ;
fflush(stdout);
}
std::cout << std::setfill(' ') << std::setw(101 - counter / (workload_size/100));
std::cout << counter*100/workload_size << "%";
fflush(stdout);
if (counter == workload_size) {
std::cout << "\n";
return;
}
}
int main(int argc, char *argvx[]) {
// check emu_environment.h for the contents of EmuEnv and also the definitions of the singleton experimental environment
EmuEnv* _env = EmuEnv::getInstance();
//parse the command line arguments
if (parse_arguments2(argc, argvx, _env)){
exit(1);
}
fstream fout1, fout2, fout3, fout4;
// fout1.open("out_delete.csv", ios::out | ios::app);
// fout2.open("out_range.csv", ios::out | ios::app);
// fout3.open("out_sec_range.csv", ios::out | ios::app);
// fout4.open("out_point_nonempty.csv", ios::out | ios::app);
// fout4.open("out_point.csv", ios::out | ios::app);
// fout1 << "Delete tile size" << ", " << "Fraction" << "," << "Delete Key" << "," << "Full Drop" << "," << "Partial Drop" << "," << "Impossible Drop" << "\n";
// fout2 << "Delete tile size" << ", " << "Selectivity" << "," << "Range Start" << "," << "Range End" << "," << "Occurrences" << "\n";
// fout3 << "Delete tile size" << ", " << "Selectivity" << "," << "Sec Range Start" << "," << "Sec Range End" << "," << "Occurrences" << "\n";
// fout4 << "Delete tile size" << ", " << "Iterations" << "," << "Sum_Page_Id" << "," << "Avg_Page_Id" << "," << "Found" << "," << "Not Found" << "\n";
// fout1.close();
// fout2.close();
// fout3.close();
// fout4.close();
// vanilla write count for 5 and 10 times insertions
// for (int i = 0; i < 10; i++) {
// insert_time = i + 1;
// std::cerr << "Issuing inserts ... " << std::endl << std::flush;
// WorkloadGenerator workload_generator;
// workload_generator.generateWorkload((long)_env->num_inserts / 10, (long)_env->entry_size, _env->correlation);
// std::cout << "Workload Generated!" << std::endl;
// int only_file_meta_data = 0;
// if (_env->delete_tile_size_in_pages > 0 && _env->lethe_new == 0)
// {
// int write_file_count = runWorkload(_env);
// std::cout << "Insert complete ... " << std::endl << std::flush;
// //DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// {
// DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// }
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// printEmulationOutput(_env);
// }
// }
// DiskMetaFile::clearAllEntries();
// return 0;
// vanilla sequential evaluation for different selectivities
// float selectivities[5] = {1, 25, 50, 75, 95};
// for (int i = 0; i < 5; i++) {
// std::cerr << "Issuing inserts ... " << std::endl << std::flush;
// WorkloadGenerator workload_generator;
// workload_generator.generateWorkload((long)_env->num_inserts, (long)_env->entry_size, _env->correlation);
// std::cout << "Workload Generated!" << std::endl;
// int only_file_meta_data = 0;
// if (_env->delete_tile_size_in_pages > 0 && _env->lethe_new == 0)
// {
// int write_file_count = runWorkload(_env);
// std::cout << "Insert complete ... " << std::endl << std::flush;
// //DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// {
// DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// }
// // each time apply 500 times range queries for experiments
// for (int j = 0; j < 500; j++) {
// Query::range_query_experiment(selectivities[i]);
// }
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// printEmulationOutput(_env);
// }
// DiskMetaFile::clearAllEntries();
// }
// return 0;
// Sequential Evaluation with Compaction for different selectivities and QueryDrivenCompactionSelectivities
// float selectivities[5] = {1, 25, 50, 75, 95};
// float QueryDrivenCompactionSelectivities[4] = {0.25, 0.5, 0.75, 1};
// // loop throught selectivities
// for (int i = 0; i < 5; i++) {
// // loop through QueryDrivenCompactionSelectivities
// for (int k = 0; k < 4; k++) {
// float QueryDrivenCompactionSelectivity = QueryDrivenCompactionSelectivities[k];
// std::cerr << "Issuing inserts ... " << std::endl << std::flush;
// WorkloadGenerator workload_generator;
// workload_generator.generateWorkload((long)_env->num_inserts, (long)_env->entry_size, _env->correlation);
// std::cout << "Workload Generated!" << std::endl;
// int only_file_meta_data = 0;
// if (_env->delete_tile_size_in_pages > 0 && _env->lethe_new == 0)
// {
// int s = runWorkload(_env);
// std::cout << "Insert complete ... " << std::endl << std::flush;
// //DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// {
// DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// }
// // each time applies consecutive range_query_compaction_experiment
// for (int j = 0; j < 100; j++) {
// Query::range_query_compaction_experiment(selectivities[i], "QueryDrivenCompactionSelectivity_sequential.csv", 1, QueryDrivenCompactionSelectivity);
// }
// Query::point_query_experiment(selectivities[i], QueryDrivenCompactionSelectivities[k], insert_time);
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// printEmulationOutput(_env);
// }
// DiskMetaFile::clearAllEntries();
// }
// }
// return 0;
// Non Sequential Evaluation with Compaction for different selectivities and QueryDrivenCompactionSelectivities
float selectivities[5] = {1, 25, 50, 75, 95};
float QueryDrivenCompactionSelectivities[4] = {0.25, 0.5, 0.75, 1};
// loop through selectivities
for (int i = 0; i < 5; i++) {
// loop through QueryDrivenCompactionSelectivities
for (int l = 0; l < 4; l++) {
QueryDrivenCompactionSelectivity = QueryDrivenCompactionSelectivities[l];
int only_file_meta_data = 0;
curr_selectivity = selectivities[i];
for (int j = 0; j < 10; j++) {
insert_time = j + 1;
std::cerr << "Issuing inserts ... " << std::endl << std::flush;
WorkloadGenerator workload_generator;
workload_generator.generateWorkload((long)_env->num_inserts / 10, (long)_env->entry_size, _env->correlation);
std::cout << "Workload Generated!" << std::endl;
if (_env->delete_tile_size_in_pages > 0 && _env->lethe_new == 0)
{
int s = runWorkload(_env);
std::cout << "Insert complete ... " << std::endl << std::flush;
//DiskMetaFile::printAllEntries(only_file_meta_data);
MemoryBuffer::getCurrentBufferStatistics();
DiskMetaFile::getMetaStatistics();
if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
{
DiskMetaFile::printAllEntries(only_file_meta_data);
MemoryBuffer::getCurrentBufferStatistics();
DiskMetaFile::getMetaStatistics();
}
// apply consecutive range_query_compaction_experiment
for (int k = 0; k < 50; k++) Query::range_query_compaction_experiment(selectivities[i], "QueryDrivenCompactionSelectivity_non_sequential_5.csv", insert_time, QueryDrivenCompactionSelectivity);
// apply consecutive point_query_experiment
for (int k = 0; k < 50; k++) Query::point_query_experiment(selectivities[i], QueryDrivenCompactionSelectivities[l], insert_time);
if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
printEmulationOutput(_env);
}
}
DiskMetaFile::clearAllEntries();
}
}
return 0;
// if (_env->num_inserts > 0)
// {
// // if (_env->verbosity >= 1)
// std::cerr << "Issuing inserts ... " << std::endl << std::flush;
// WorkloadGenerator workload_generator;
// workload_generator.generateWorkload((long)_env->num_inserts, (long)_env->entry_size, _env->correlation);
// std::cout << "Workload Generated!" << std::endl;
// int only_file_meta_data = 0;
// if(_env->delete_tile_size_in_pages > 0 && _env->lethe_new == 0)
// {
// int s = runWorkload(_env);
// std::cout << "Insert complete ... " << std::endl << std::flush;
// //DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// {
// DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// }
// // cout << "Running Range Query..." << endl;
// // Query::range_query_experiment();
// // Query::checkDeleteCount(Query::delete_key);
// // Query::rangeQuery(Query::range_start_key, Query::range_end_key);
// // Query::secondaryRangeQuery(Query::sec_range_start_key, Query::sec_range_end_key);
// // Query::pointQueryRunner(Query::iterations_point_query);
// // cout << "H" << "\t"
// // << "DKey" << "\t"
// // << "Full_Drop" << "\t"
// // << "Partial_Drop" << "\t"
// // << "No_Drop" << "\t\t"
// // << "RKEYs" << "\t"
// // << "Occurance" << "\t"
// // << "SRKEYs" << "\t"
// // << "Occurance" << "\t"
// // << "P_iter" << "\t\t"
// // << "Sumpid" << "\t\t"
// // << "Avgpid" << "\t\t"
// // << "Found" << "\t\t"
// // << "NtFound" << "\n";
// // cout << _env->delete_tile_size_in_pages;
// // cout.setf(ios::right);
// // cout.precision(4);
// // cout.width(10);
// // cout << Query::delete_key;
// // cout.width(11);
// // cout << Query::complete_delete_count;
// // cout.width(18);
// // cout << Query::partial_delete_count;
// // cout.width(12);
// // cout << Query::not_possible_delete_count;
// // cout.width(12);
// // cout << Query::range_start_key << " " << Query::range_end_key;
// // cout.width(9);
// // cout << Query::range_occurances;
// // cout.width(11);
// // cout << Query::sec_range_start_key << " " << Query::sec_range_end_key;
// // cout.width(9);
// // cout << Query::secondary_range_occurances;
// // cout.width(15);
// // cout << Query::iterations_point_query;
// // cout.width(16);
// // cout << Query::sum_page_id;
// // cout.width(16);
// // cout << Query::sum_page_id/(Query::found_count * 1.0);
// // cout.width(15);
// // cout << Query::found_count;
// // cout.width(17);
// // cout << Query::not_found_count << "\n";
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// printEmulationOutput(_env);
// }
// else if (_env->delete_tile_size_in_pages == -1 && _env->lethe_new == 0)
// {
// for (int i = 1; i <= _env->buffer_size_in_pages; i = i*2)
// {
// cout << "Running for delete tile size: " << i << " ..." << endl;
// _env->delete_tile_size_in_pages = i;
// int s = runWorkload(_env);
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// {
// DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// }
// //cout << "Running Delete Query..." << endl;
// //Query::delete_query_experiment();
// cout << "Running Range Query..." << endl;
// Query::range_query_experiment();
// //cout << "Running Secondary Range Query..." << endl;
// //Query::sec_range_query_experiment();
// //cout << "Running Point Query..." << endl;
// // Query::point_query_experiment();
// DiskMetaFile::clearAllEntries();
// WorkloadExecutor::counter = 0;
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// printEmulationOutput(_env);
// }
// }
// else if (_env->lethe_new == 1 || _env->lethe_new == 2)
// {
// int s = runWorkload(_env);
// // DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// {
// DiskMetaFile::printAllEntries(only_file_meta_data);
// MemoryBuffer::getCurrentBufferStatistics();
// DiskMetaFile::getMetaStatistics();
// }
// cout << "Running Delete Query..." << endl;
// Query::delete_query_experiment();
// cout << "Running Range Query..." << endl;
// Query::range_query_experiment();
// cout << "Running Secondary Range Query..." << endl;
// Query::sec_range_query_experiment();
// cout << "Running Point Query..." << endl;
// Query::new_point_query_experiment();
// DiskMetaFile::clearAllEntries();
// WorkloadExecutor::counter = 0;
// printEmulationOutput(_env);
// if (MemoryBuffer::verbosity == 1 || MemoryBuffer::verbosity == 2 || MemoryBuffer::verbosity == 3)
// printEmulationOutput(_env);
// }
// //srand(time(0));
// //WorkloadExecutor::getWorkloadStatictics(_env);
// //assert(_env->num_inserts == inserted);
// }
// return 0;
}
int runWorkload(EmuEnv* _env) {
MemoryBuffer* buffer_instance = MemoryBuffer::getBufferInstance(_env);
WorkloadExecutor workload_executer;
// reading from file
ifstream workload_file;
workload_file.open("workload.txt");
assert(workload_file);
int counter = 0;
int write_file_count = 0;
while(!workload_file.eof()) {
char instruction;
long sortkey;
long deletekey;
string value;
workload_file >> instruction >> sortkey >> deletekey >> value;
switch (instruction)
{
case 'I':
//std::cout << instruction << " " << sortkey << " " << deletekey << " " << value << std::endl;
write_file_count += workload_executer.insert(sortkey, deletekey, value);
break;
//default:
//break;
}
instruction='\0';
counter++;
if(!(counter % (_env->num_inserts/100))){
showProgress(_env->num_inserts, counter);
}
}
fstream fout2;
fout2.open("insert_write_file_count.csv", ios::out | ios::app);
bool is_empty = (fout2.tellp() == 0);
if (is_empty) {
fout2 << "Insert Num, Curr Selectivity, QueryDrivenCompactionSelectivity, Write File Count, Insert Time" << "\n";
}
fout2 << _env->num_inserts << "," << curr_selectivity << "," << QueryDrivenCompactionSelectivity << "," << write_file_count << "," << insert_time << endl;
return write_file_count;
}
int parse_arguments2(int argc,char *argvx[], EmuEnv* _env) {
args::ArgumentParser parser("KIWI Emulator", "");
args::Group group1(parser, "This group is all exclusive:", args::Group::Validators::DontCare);
args::ValueFlag<int> size_ratio_cmd(group1, "T", "The size ratio of the tree [def: 2]", {'T', "size_ratio"});
args::ValueFlag<int> buffer_size_in_pages_cmd(group1, "P", "Size of the memory buffer in terms of pages [def: 128]", {'P', "buffer_size_in_pages"});
args::ValueFlag<int> entries_per_page_cmd(group1, "B", "No of entries in one page [def: 128]", {'B', "entries_per_page"});
args::ValueFlag<int> entry_size_cmd(group1, "E", "Entry size in bytes [def: 128 B]", {'E', "entry_size"});
args::ValueFlag<long> buffer_size_cmd(group1, "M", "Memory size (PBE) [def: 2 MB]", {'M', "memory_size"});
args::ValueFlag<int> delete_tile_size_in_pages_cmd(group1, "delete_tile_size_in_pages", "Size of a delete tile in terms of pages [def: -1]", {'h', "delete_tile_size_in_pages"});
args::ValueFlag<long> file_size_cmd(group1, "file_size", "file size [def: 256 KB]", {"file_size"});
args::ValueFlag<long long> num_inserts_cmd(group1, "#inserts", "The number of unique inserts to issue in the experiment [def: 0]", {'i', "num_inserts"});
args::ValueFlag<int> cor_cmd(group1, "#correlation", "Correlation between sort key and delete key [def: 0]", {'c', "correlation"});
args::ValueFlag<int> verbosity_cmd(group1, "verbosity", "The verbosity level of execution [0,1,2; def:0]", {'V', "verbosity"});
args::ValueFlag<int> lethe_new_cmd(group1, "lethe_new", "Specific h across tree(0), Optimal h across tree(1) or different optimal h in each levels(2) [0, 1, 2; def:0]", {'X', "lethe_new"});
args::ValueFlag<int> SRD_cmd(group1, "SRD", "Count of secondary range delete [def:1]", {'I', "SRD"});
args::ValueFlag<int> EPQ_cmd(group1, "EPQ", "Count of empty point queries [def:1000000]", {'J', "EPQ"});
args::ValueFlag<int> PQ_cmd(group1, "PQ", "Count of non-empty point queries [def:1000000]", {'K', "PQ"});
args::ValueFlag<int> SRQ_cmd(group1, "SRQ", "Count of short range queries [def:1]", {'L', "SRQ"});
args::ValueFlag<int> delete_key_cmd(group1, "delete_key", "Delete all keys less than DK [def:700]", {'D', "delete_key"});
args::ValueFlag<int> range_start_key_cmd(group1, "range_start_key", "Starting key of the range query [def:2000]", {'S', "range_start_key"});
args::ValueFlag<int> range_end_key_cmd(group1, "range_end_key", "Ending key of the range query [def:5000]", {'F', "range_end_key"});
args::ValueFlag<int> sec_range_start_key_cmd(group1, "sec_range_start_key", "Starting key of the secondary range query [def:200]", {'s', "sec_range_start_key"});
args::ValueFlag<int> sec_range_end_key_cmd(group1, "sec_range_end_key", "Ending key of the secondary range query [def:500]", {'f', "sec_range_end_key"});
args::ValueFlag<int> iterations_point_query_cmd(group1, "iterations_point_query", "Number of point queries to be performed [def:100000]", {'N', "iterations_point_query"});
try
{
parser.ParseCLI(argc, argvx);
}
catch (args::Help&)
{
std::cout << parser;
exit(0);
// return 0;
}
catch (args::ParseError& e)
{
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
}
catch (args::ValidationError& e)
{
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
}
_env->size_ratio = size_ratio_cmd ? args::get(size_ratio_cmd) : 2;
_env->buffer_size_in_pages = buffer_size_in_pages_cmd ? args::get(buffer_size_in_pages_cmd) : 128;
_env->entries_per_page = entries_per_page_cmd ? args::get(entries_per_page_cmd) : 128;
_env->entry_size = entry_size_cmd ? args::get(entry_size_cmd) : 128;
_env->buffer_size = buffer_size_cmd ? args::get(buffer_size_cmd) : _env->buffer_size_in_pages * _env->entries_per_page * _env->entry_size;
_env->delete_tile_size_in_pages = delete_tile_size_in_pages_cmd ? args::get(delete_tile_size_in_pages_cmd) : -1;
_env->file_size = file_size_cmd ? args::get(file_size_cmd) : _env->buffer_size;
_env->num_inserts = num_inserts_cmd ? args::get(num_inserts_cmd) : 0;
_env->verbosity = verbosity_cmd ? args::get(verbosity_cmd) : 0;
_env->correlation = cor_cmd ? args::get(cor_cmd) : 0;
_env->lethe_new = lethe_new_cmd ? args::get(lethe_new_cmd) : 0;
_env->srd_count = SRD_cmd ? args::get(SRD_cmd) : 1;
_env->epq_count = EPQ_cmd ? args::get(EPQ_cmd) : 1000000;
_env->pq_count = PQ_cmd ? args::get(PQ_cmd) : 1000000;
_env->srq_count = SRQ_cmd ? args::get(SRQ_cmd) : 10000;
calculateDeleteTileSize(_env);
Query::delete_key = delete_key_cmd ? args::get(delete_key_cmd) : 700;
Query::range_start_key = range_start_key_cmd ? args::get(range_start_key_cmd) : 2000;
Query::range_end_key = range_end_key_cmd ? args::get(range_end_key_cmd) : 5000;
Query::sec_range_start_key = sec_range_start_key_cmd ? args::get(sec_range_start_key_cmd) : 200;
Query::sec_range_end_key = sec_range_end_key_cmd ? args::get(sec_range_end_key_cmd) : 500;
Query::iterations_point_query = iterations_point_query_cmd ? args::get(iterations_point_query_cmd) : 100000;
return 0;
}
void calculateDeleteTileSize(EmuEnv* _env)
{
// calculation of Kiwi++ (following desmos)
float num = (_env->num_inserts * (_env->size_ratio - 1) * 1.0);
float denum = (_env->buffer_size_in_pages * _env->entries_per_page * _env->size_ratio * 1.0);
_env->level_count = ceil(log(num/denum)/log(_env->size_ratio));
float E[20] = {-1};
float F[20] = {-1};
float G[20] = {-1};
float R[20] = {-1};
float temp_sum = 0;
for (int j = 1; j <= _env->level_count; j++)
{
temp_sum += pow(_env->size_ratio, j);
}
for (int i = 1; i <= _env->level_count; i++)
{
E[i] = pow(_env->size_ratio, i)/(temp_sum * 1.0);
}
for (int i = 1; i <= _env->level_count; i++)
{
float tempsum2 = 0;
for (int j = 1; j <= i - 1; j++)
{
tempsum2 += pow(_env->size_ratio, j);
}
F[i] = (tempsum2 * 1.0)/temp_sum;
}
for (int i = 1; i <= _env->level_count; i++)
{
G[i] = 1 - E[i] - F[i];
}
float phi = 0.0081925;
for (int i = 1; i <= _env->level_count; i++)
{
R[i] = (pow((_env->size_ratio * 1.0),((_env->size_ratio * 1.0)/(_env->size_ratio - 1))) * phi)/(pow(_env->size_ratio,_env->level_count + 1 - i));
}
for (int i = 1; i <= _env->level_count; i++)
{
float num2 = _env->buffer_size_in_pages * pow(_env->size_ratio, i) * _env->srd_count;
float denum2 = ((_env->epq_count + (_env->pq_count * G[i])) * R[i]) + ((R[i] * _env->pq_count * E[i]) / 2) + _env->srq_count;
_env->variable_delete_tile_size_in_pages[i] = round (pow(num2/denum2, 0.5));
if (_env->variable_delete_tile_size_in_pages[i] == 0)
_env->variable_delete_tile_size_in_pages[i] = 1;
if (_env->variable_delete_tile_size_in_pages[i] > _env->buffer_size_in_pages)
_env->variable_delete_tile_size_in_pages[i] = _env->buffer_size_in_pages;
// cout << _env->variable_delete_tile_size_in_pages[i] << " " << endl;
}
if (_env->lethe_new == 1)
{
// Optimal h for Kiwi
float phi_opt = ((pow(_env->size_ratio,(_env->size_ratio*1.0/(_env->size_ratio-1)*1.0)))/_env->size_ratio)*phi;
float num_opt = (_env->srd_count * _env->num_inserts * 1.0)/_env->entries_per_page;
float denum_opt = ((_env->epq_count + _env->pq_count) * phi_opt * _env->level_count) + (_env->level_count * _env->srq_count);
_env->delete_tile_size_in_pages = round (pow(num_opt/denum_opt, 0.5));
if (_env->delete_tile_size_in_pages == 0)
_env->delete_tile_size_in_pages = 1;
if (_env->delete_tile_size_in_pages > _env->buffer_size_in_pages)
_env->delete_tile_size_in_pages = _env->buffer_size_in_pages;
std::cout << "Optimal Delete Tile Size: " << _env->delete_tile_size_in_pages << std::endl;
}
}
void printEmulationOutput(EmuEnv* _env) {
//double percentage_non_zero_result_queries = ceil((100 * _env->nonzero_to_zero_ratio) / (_env->nonzero_to_zero_ratio + 1.0));
//if (_env->verbosity >= 1)
std::cout << "T, P, B, E, M, h, file_size, #I \n";
std::cout << _env->size_ratio << ", ";
std::cout << _env->buffer_size_in_pages << ", ";
std::cout << _env->entries_per_page << ", ";
std::cout << _env->entry_size << ", ";
std::cout << _env->buffer_size << ", ";
std::cout << _env->delete_tile_size_in_pages << ", ";
std::cout << _env->file_size << ", ";
std::cout << _env->num_inserts ;
std::cout << std::endl;
std::cout << "Kiwi++,\tSRD,\tEPQ,\tPQ,\tSRQ\n";
std::cout << _env->lethe_new << "\t";
std::cout << _env->srd_count << "\t";
std::cout << _env->epq_count << "\t";
std::cout << _env->pq_count << "\t";
std::cout << _env->srq_count << "\t";
std::cout << std::endl;
if (_env->lethe_new == 2)
{
std::cout << "Delete tiles size : " << std::endl;
for (int i = 1; i <= _env->level_count; i++)
{
std::cout << _env->variable_delete_tile_size_in_pages[i] << "\t";
}
std::cout << std::endl;
}
}