-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
161 lines (140 loc) · 4.27 KB
/
index.js
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
// libraries
const now = require('performance-now');
const chalk = require('chalk');
const { plot } = require('nodeplotlib');
const minimist = require('minimist');
// own code modules
const { parseQueriesFromFile } = require('./query');
const { parseCsvFile } = require('./db/csvInit');
const {
executeSingleQuery: standarddbExecute,
} = require('./evaluators/standarddb');
const {
executeSingleQuery: recursivedbExecute,
} = require('./evaluators/recursivedb');
const DB = require('./db'); // imported for type annotation
const {
pageFetchTime,
maxNoOfRecsPerFile,
cacheOptions,
scales,
blockJoinSize,
noOfRuns,
} = require('./config');
const { logTime } = require('./utilities');
const args = minimist(process.argv.slice(2));
const { batchNumber, queryNumber } = args;
console.log(
`Starting DB test with the following options (change in ${chalk.blackBright(
'./config.js'
)}):
Maximum number of records per page: ${chalk.green(maxNoOfRecsPerFile)}
Page buffer capacity: ${chalk.green(cacheOptions.max + ' pages')}
Page fetch time (to simulate physical storage access time): ${chalk.green(
pageFetchTime + 'ms'
)}
Block join block size: ${chalk.green(blockJoinSize)}\n`
);
// PARSE SQL QUERY
let start = now();
const parsedQueries = parseQueriesFromFile(`./dataset/query${queryNumber}.txt`);
let end = now();
logTime(start, end, 'parsing recursive sql queries');
console.info(chalk.red('\nStandardDB algorithm test\n'));
const standardtimes = [];
scales.forEach((scale) => {
console.info(
`\nDoing bench${batchNumber} while keeping ${scale}% of records in the csv tables\n`
);
// LOAD TABLES FROM CSV INTO DB
start = now();
for (const tableName of ['a', 'b', 'c']) {
parseCsvFile(
`./dataset/bench${batchNumber}_${tableName}.csv`,
tableName,
scale
);
}
end = now();
logTime(start, end, 'loading data into db from csv files');
DB.printStats();
// Execute queries
let totalTime = 0;
for (let run = 0; run < noOfRuns; run++) {
let runStart = now();
parsedQueries.forEach((query) => {
start = now();
standarddbExecute(query);
end = now();
});
let runEnd = now();
logTime(runStart, runEnd, `time for standarddb to do run ${run}`);
if (run > 0) totalTime += runEnd - runStart;
parsedQueries.forEach((query) => {
DB.drop(query.resultTableName);
});
}
console.log(
`\nAverage time for standarddb to do a run is ${chalk.green(
(totalTime / (1000 * (noOfRuns - 1))).toFixed(3)
)}s`
);
standardtimes.push((totalTime / (1000 * (noOfRuns - 1))).toFixed(3));
DB.dropAllTables();
});
DB.dropAllTables();
console.info(chalk.red('\nRecursiveDB algorithm test\n'));
const recursiveTimes = [];
scales.forEach((scale) => {
console.info(
`\nDoing bench${batchNumber} while keeping ${scale}% of records in the csv tables\n`
);
// LOAD TABLES FROM CSV INTO DB
start = now();
for (const tableName of ['a', 'b', 'c']) {
parseCsvFile(
`./dataset/bench${batchNumber}_${tableName}.csv`,
tableName,
scale
);
}
end = now();
logTime(start, end, 'loading data into db from csv files');
DB.printStats();
// Execute queries
let totalTime = 0;
for (let run = 0; run < noOfRuns; run++) {
let runStart = now();
parsedQueries.forEach((query) => {
start = now();
recursivedbExecute(query);
end = now();
});
let runEnd = now();
logTime(runStart, runEnd, `recursivedb to do run ${run}`);
if (run > 0) totalTime += runEnd - runStart;
parsedQueries.forEach((query) => {
DB.drop(query.resultTableName);
});
}
console.log(
`\nAverage time for recursivedb to do a run is ${chalk.green(
(totalTime / (1000 * (noOfRuns - 1))).toFixed(3)
)}s`
);
recursiveTimes.push((totalTime / (1000 * (noOfRuns - 1))).toFixed(3));
DB.dropAllTables();
});
const data = [
{ x: scales, y: standardtimes, type: 'line', name: 'StandardDB times' },
{ x: scales, y: recursiveTimes, type: 'line', name: 'RecursiveDB times' },
];
const xAxisTemplate = {
title: 'Percentage of original records kept',
};
const yAxisTemplate = {
title: 'Time taken (s)',
};
const layout = { xaxis: xAxisTemplate, yaxis: yAxisTemplate };
console.info('\nRendering plot at http://localhost:8991/plots/0/index.html');
plot(data, layout);