-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexperiment.cpp
More file actions
139 lines (118 loc) · 4.31 KB
/
Copy pathexperiment.cpp
File metadata and controls
139 lines (118 loc) · 4.31 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
#include <gtest/gtest.h>
#include <math.h>
#include <thread>
#include <chrono>
#include <atomic>
#include "../include/buffer_tree.h"
#define KB (uint64_t (1 << 10))
#define MB (uint64_t (1 << 20))
#define GB (uint64_t (1 << 30))
static bool shutdown = false;
static std::atomic<uint64_t> upd_processed;
// queries the buffer tree and verifies that the data
// returned makes sense
// Should be run in a seperate thread
void querier(BufferTree *buf_tree, int nodes) {
data_ret_t data;
while(true) {
bool valid = buf_tree->get_data(data);
if (valid) {
Node key = data.first;
std::vector<Node> updates = data.second;
// verify that the updates are all between the correct nodes
for (Node upd : updates) {
// printf("edge to %d\n", upd.first);
ASSERT_EQ(nodes - (key + 1), upd) << "key " << key;
upd_processed += 1;
}
}
else if(shutdown)
return;
}
}
void progress(const uint64_t num_updates) {
while(true) {
sleep(5);
uint64_t cur = upd_processed.load();
printf("number of insertions processed: %lu %f%% \r", cur, cur/((double)num_updates/100));
fflush(stdout);
if (upd_processed == num_updates) {
printf("number of insertions processed: DONE \n");
break;
}
}
}
// helper function to run a basic test of the buffer tree with
// various parameters
// this test only works if the depth of the tree does not exceed 1
// and no work is claimed off of the work queue
// to work correctly num_updates must be a multiple of nodes
void run_test(const int nodes, const uint64_t num_updates, const uint64_t buffer_size,
const int branch_factor, const int threads=1) {
printf("Running Test: nodes=%i num_updates=%lu buffer_size %lu branch_factor %i\n",
nodes, num_updates, buffer_size, branch_factor);
BufferTree *buf_tree = new BufferTree("./test_", buffer_size, branch_factor, nodes, threads, 16, true);
shutdown = false;
upd_processed = 0;
std::thread query_threads[threads];
for (int t = 0; t < threads; t++) {
query_threads[t] = std::thread(querier, buf_tree, nodes);
}
std::thread progress_thr(progress, num_updates);
auto start = std::chrono::steady_clock::now();
for (uint64_t i = 0; i < num_updates; i++) {
update_t upd;
upd.first = i % nodes;
upd.second = (nodes - 1) - (i % nodes);
buf_tree->insert(upd);
}
std::chrono::duration<double> delta = std::chrono::steady_clock::now() - start;
printf("insertions took %f seconds: average rate = %f\n", delta.count(), num_updates/delta.count());
buf_tree->force_flush();
shutdown = true;
buf_tree->set_non_block(true); // tell any waiting threads to reset
delta = std::chrono::steady_clock::now() - start;
printf("insert+force_flush took %f seconds: average rate = %f\n", delta.count(), num_updates/delta.count());
for (int t = 0; t < threads; t++) {
query_threads[t].join();
}
progress_thr.join();
delete buf_tree;
}
TEST(Experiment, LargeStandard) {
const int nodes = 512;
const uint64_t num_updates = MB << 5;
const uint64_t buf = MB;
const int branch = 8;
run_test(nodes, num_updates, buf, branch);
}
TEST(Experiment, LargeWide) {
const int nodes = 512;
const uint64_t num_updates = MB << 5;
const uint64_t buf = MB;
const int branch = 16;
run_test(nodes, num_updates, buf, branch);
}
TEST(Experiment, ExtraLarge) {
const int nodes = 1024;
const uint64_t num_updates = MB << 8;
const uint64_t buf = MB << 1;
const int branch = 16;
run_test(nodes, num_updates, buf, branch);
}
TEST(SteadyState, HugeExperiment) {
const int nodes = 250000;
const uint64_t num_updates = GB << 2; // 8 billion
const uint64_t buf = MB;
const int branch = 64;
const int threads = 10;
run_test(nodes, num_updates, buf, branch, threads);
}
TEST(SteadyState, BigFanoutExperiment) {
const int nodes = 250000;
const uint64_t num_updates = GB << 2; // 8 billion
const uint64_t buf = MB;
const int branch = 512;
const int threads = 10;
run_test(nodes, num_updates, buf, branch, threads);
}