-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
168 lines (116 loc) · 4.26 KB
/
main.cpp
File metadata and controls
168 lines (116 loc) · 4.26 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
#include <iostream>
#include "DB.h"
#include "Query.h"
#include <fstream>
#include <sstream>
#include <cassert>
#include <queue>
#include <chrono>
#include "IO.h"
#include "argument_helper.h"
#include "random"
using namespace std;
unsigned sliding_window_size = 0;
unsigned sliding_window_factor = 5;
unsigned sliding_window_time_range = 0;
clock_t start_time;
double scale_fac = 1;
int oper_idx = -1;
int output_db_oper_idx = -2; ///< -2: do not output. -1: output random partial db(because # peak answers = 0.)
int all_oper_num = -1;
extern vector<double> selectivity_recorder;
extern vector<double> decide_latencies;
void Test(Buffer& input_buf, Query& query)
{
DB db{};
db.SetQuery(query);
start_time = clock();
oper_idx = 0;
vector<double> latencies;
all_oper_num = input_buf.GetOperNum();
while(true) {
const auto& oper = input_buf.GetNextOper();
if (oper.GetType() == Operation::Type::null) break;
db.HandleOper(oper);
if(oper_idx%10000 == 0){
if((clock() - start_time) / (double)CLOCKS_PER_SEC > 3600*4) /// more than two hours
{
cout<<"take more than 4h to process. killed.\n";
exit(0);
}
}
oper_idx++;
if(oper_idx == start_period_length) {
start_time = clock();
latencies.clear();
decide_latencies.clear();
}
}
auto end_time = clock();
double tail_lat_100;
double tail_lat_10000;
double tail_lat_1000;
double max_lat;
cout<<"time(sec): "<<(end_time - start_time) / (double)CLOCKS_PER_SEC <<endl;
}
unsigned epsilon_reciprocal = 100000;
string dynamic_stream_fn;
string schema_file;
string query_file;
string static_stream_fn;
string primary_key_fn;
struct InputParam
{
string schema_fn;
string query_fn;
string st_stream_fn;
string dyn_stream_fn;
string pri_key_fn;
int output_database_oper_idx = -2;
int sliding_window_fac = 5;
int sliding_window_size_ = 0; ///< only one of sliding_window_fac and sliding_window_size_ is valid.
int sliding_window_time_range_ = 0;
int epsilon_reciprocal_ = 100000;
void SetDefaultValue() const {
schema_file=schema_fn;
query_file=query_fn;
static_stream_fn=st_stream_fn;
dynamic_stream_fn=dyn_stream_fn;
primary_key_fn = pri_key_fn;
sliding_window_factor = sliding_window_fac;
sliding_window_size = sliding_window_size_;
sliding_window_time_range = sliding_window_time_range_;
output_db_oper_idx = output_database_oper_idx;
epsilon_reciprocal = epsilon_reciprocal_;
}
}input_params;
void ArgumentParser(int argc, char ** argv, InputParam& input_param)
{
dsr::Argument_helper ah;
ah.new_string("schema_fn","",input_param.schema_fn);
ah.new_string("query_fn","",input_param.query_fn);
ah.new_string("static_stream_fn","",input_param.st_stream_fn);
ah.new_string("dynamic_stream_fn","",input_param.dyn_stream_fn);
ah.new_string("primary_key_fn","",input_param.pri_key_fn);
// ah.new_named_int('s', "sliding_window_fac", "sliding window fac", "sliding window fac", input_param.sliding_window_fac);
// ah.new_named_int('w', "sliding_window_size", "sliding_window_size", "sliding_window_size", input_param.sliding_window_size_);
// ah.new_named_int('t', "sliding_window_time_range", "sliding_window_time_range", "sliding_window_time_range", input_param.sliding_window_time_range_);
ah.new_named_int('l', "start_period_length", "start_period_length", "start_period_length", start_period_length);
// ah.new_named_int('o', "output_db_oper_idx", "output_db_oper_idx", "output_db_oper_idx", input_param.output_database_oper_idx);
// ah.new_named_int('e', "epsilon_reciprocal", "epsilon_reciprocal", "epsilon_reciprocal", input_param.epsilon_reciprocal_);
ah.process(argc, argv);
}
std::ranlux24_base r;
int main(int argc, char* argv[]) {
std::random_device rd;
unsigned int seed = rd();
r = ranlux24_base(seed);
ArgumentParser(argc,argv,input_params);
input_params.SetDefaultValue();
Buffer input_buf;
Query query;
PrepareQuery(query);
PrepareData(input_buf, query);
Test(input_buf,query);
return 0;
}