-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsyncBench.cpp
134 lines (91 loc) · 3.09 KB
/
syncBench.cpp
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
#include <string>
#include <iostream>
#include <stdexcept>
#include <functional>
#include <vector>
#include <bitset>
#include <random>
#include "quadrable.h"
#include "quadrable/transport.h"
#include "quadrable/debug.h"
namespace quadrable {
void doIt() {
::system("mkdir -p testdb/ ; rm testdb/*.mdb");
std::string dbDir = "testdb/";
lmdb::env lmdb_env = lmdb::env::create();
lmdb_env.set_max_dbs(64);
lmdb_env.set_mapsize(1UL * 1024UL * 1024UL * 1024UL * 1024UL);
lmdb_env.open(dbDir.c_str(), MDB_CREATE, 0664);
lmdb_env.reader_check();
quadrable::Quadrable db;
{
auto txn = lmdb::txn::begin(lmdb_env, nullptr, 0);
db.init(txn);
txn.commit();
}
auto txn = lmdb::txn::begin(lmdb_env, nullptr, 0);
std::mt19937 rnd;
rnd.seed(0);
for (uint loopVar = 10; loopVar < 20'001; loopVar *= 2) {
uint64_t numElems = 100000;
uint64_t maxElem = numElems;
uint64_t numAlterations = loopVar;
db.checkout();
{
auto c = db.change();
for (uint64_t i = 0; i < numElems; i++) {
auto n = rnd() % maxElem;
c.put(quadrable::Key::fromInteger(n), std::to_string(n));
}
c.apply(txn);
}
uint64_t origNodeId = db.getHeadNodeId(txn);
db.fork(txn);
{
auto chg = db.change();
for (uint64_t i = 0; i < numAlterations; i++) {
auto n = numElems + rnd() % maxElem;
auto action = rnd() % 2;
if (action == 0) {
chg.put(quadrable::Key::fromInteger(n), "");
} else if (action == 1) {
chg.del(quadrable::Key::fromInteger(n));
}
}
chg.apply(txn);
}
uint64_t newNodeId = db.getHeadNodeId(txn);
auto newKey = db.rootKey(txn);
Quadrable::Sync sync(&db);
sync.init(txn, origNodeId);
uint64_t bytesDown = 0;
uint64_t bytesUp = 0;
uint64_t roundTrips = 0;
while(1) {
auto reqs = sync.getReqs(txn, 10000);
uint64_t reqSize = transport::encodeSyncRequests(reqs).size();
bytesUp += reqSize;
if (reqs.size() == 0) break;
auto resps = db.handleSyncRequests(txn, newNodeId, reqs, 100000);
uint64_t respSize = transport::encodeSyncResponses(resps).size();
bytesDown += respSize;
sync.addResps(txn, reqs, resps);
roundTrips++;
std::cout << "RT: " << roundTrips << " up: " << reqSize << " down: " << respSize << std::endl;
}
db.checkout(sync.nodeIdShadow);
if (db.rootKey(txn) != newKey) throw quaderr("NOT EQUAL AFTER IMPORT");
std::cout << loopVar << "," << roundTrips << "," << bytesUp << "," << bytesDown << std::endl;
}
txn.abort();
}
}
int main() {
try {
quadrable::doIt();
} catch (const std::runtime_error& error) {
std::cerr << "Test failure: " << error.what() << std::endl;
return 1;
}
return 0;
}