forked from haubenmi/navigating-cloud-oltp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogService.cpp
More file actions
127 lines (117 loc) · 7.17 KB
/
LogService.cpp
File metadata and controls
127 lines (117 loc) · 7.17 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
#include "LogService.hpp"
#include "Architecture.hpp"
#include "infra/Math.hpp"
#include <sstream>
#include <iomanip>
//--------------------------------------------------------------------------------
using namespace std;
using namespace infra;
//--------------------------------------------------------------------------------
unique_ptr<InstanceStorageLogService> InstanceStorageLogService::assemble(const Parameter& p, Primary& prim) {
auto inst = prim.reserveInstanceStorage(p.getRequiredLogStorage(), Rate::zero, p.getLogWritesRequiredForUpdates(InstanceStorage::MaxIOPSize));
if (inst) {
return make_unique<InstanceStorageLogService>(p, prim, *inst);
} else {
return nullptr;
}
}
//--------------------------------------------------------------------------------
Rate InstanceStorageLogService::getUpdateOps() const {
auto logWritesPerUpdate = parameter.groupCommit ? ((parameter.getLogRecordSize() * 1.0) / InstanceStorage::MaxIOPSize) : divRoundUp(parameter.getLogRecordSize(), InstanceStorage::MaxIOPSize);
return storage.writes / logWritesPerUpdate;
}
//--------------------------------------------------------------------------------
InstanceStorageLogService::InstanceStorageLogService(const Parameter& p, Primary& prim, InstanceStorageAllotment inst)
: LogService(p), primary{prim}, storage{inst} {}
//--------------------------------------------------------------------------------
Durability InstanceStorageLogService::getDurability() const {
// The probability of being durable is that we are durable in each month
double avail = primary.n.getAvailability().numericValue;
double d = std::pow(avail, 12);
return Durability{d};
}
//--------------------------------------------------------------------------------
Price EBSLogService::getPrice() const { return Price::zero; }
//--------------------------------------------------------------------------------
EBSLogService::EBSLogService(const Parameter& p, Primary& prim, EBSAllotment ebs)
: LogService{p}, primary{prim}, ebs{ebs} {}
//--------------------------------------------------------------------------------
Rate EBSLogService::getUpdateOps() const {
auto logWritesPerUpdate = parameter.groupCommit ? ((parameter.getLogRecordSize() * 1.0) / EBS::maxIopSize) : divRoundUp(parameter.getLogRecordSize(), EBS::maxIopSize);
return ebs.iops / logWritesPerUpdate;
}
//--------------------------------------------------------------------------------
Durability EBSLogService::getDurability() const { return EBS::getDurability(ebs.type); }
//--------------------------------------------------------------------------------
unique_ptr<EBSLogService> EBSLogService::assemble(const Parameter& p, Primary& prim, EBS::Type t) {
auto logWrites = p.getLogWritesRequiredForUpdates(EBS::maxIopSize);
auto requiredBandwidth = p.requiredUpdateOps.rate * p.getLogRecordSize();
auto logStorage = p.getRequiredLogStorage();
if (auto ebs = prim.addEBSCapacity(t, logStorage, logWrites, requiredBandwidth, p.groupCommit ? EBS::maxIopSize : p.getLogRecordSize())) {
return make_unique<EBSLogService>(p, prim, *ebs);
}
return nullptr;
}
//--------------------------------------------------------------------------------
string EBSLogService::getDescription() const { return ebs.describe(); }
//--------------------------------------------------------------------------------
string Ec2LogService::getDescription() const {
stringstream res;
res << setprecision(2) << logNodeFraction;
res << "x" << logNode.name;
return res.str();
}
//--------------------------------------------------------------------------------
double Ec2LogService::computeScale(const Parameter& p, const Node& logNode, unsigned logTargets) {
if (p.requiredUpdateOps == Rate::zero) {
return 0.0;
}
double storageScale = p.getRequiredLogStorage() * getReplication() / logNode.instanceStorage.getUsableSize();
// The log node must be able to receive all writes via the network
double networkReadScale = (p.requiredUpdateOps * getReplication()) / (logNode.network.getReadLimit() / p.getLogRecordSize());
// We do not need to write log records instantly, but can rather batch them
// double logWriteScale = requiredLogWriteOps / logNode.instanceStorage.getWriteOps().rate;
// The node must however be able to handle the throughput
double logVolumeWriteScale = (p.requiredUpdateOps.rate * getReplication() * p.getLogRecordSize()) / logNode.instanceStorage.getWriteThroughput();
double logNetworkWriteScale = (p.requiredUpdateOps * p.getLogRecordSize() * logTargets) / logNode.network.getWriteLimit();
return vmaxafter(storageScale, networkReadScale, logVolumeWriteScale, logNetworkWriteScale);
}
//--------------------------------------------------------------------------------
// Uses EBS
uint64_t Ec2LogService::getMaxIopSize() const { return EBS::maxIopSize; }
//--------------------------------------------------------------------------------
unique_ptr<Ec2LogService> Ec2LogService::assemble(const Parameter& p, Primary& prim, const Node& logNode, unsigned replication) {
auto logWrites = p.getLogWritesRequiredForUpdates(EBS::maxIopSize);
auto throughput = p.requiredUpdateOps.rate * p.getLogRecordSize();
auto size = p.getRequiredLogStorage();
// Conceptually the EBS device belongs to the log service, but physically it is attached to the primary
if (auto ebs = prim.addEBSCapacity(EBS::Type::io2, size, logWrites, throughput, p.groupCommit ? EBS::maxIopSize : p.getLogRecordSize())) {
// Prohibit scaling over one log node for now
auto logTargets = p.numSecondaries + replication;
auto scale = computeScale(p, logNode, logTargets);
if (scale > 1.0) return nullptr;
return make_unique<Ec2LogService>(p, logNode, *ebs, scale, logTargets);
}
return nullptr;
}
//--------------------------------------------------------------------------------
Latency Ec2LogService::getCommitLatency() const { return EBS::writeLatency; }
//--------------------------------------------------------------------------------
Durability Ec2LogService::getDurability() const { return EBS::getDurability(logEBSDevice.type); }
//--------------------------------------------------------------------------------
Rate Ec2LogService::getUpdateOps() const {
auto& p = parameter;
// On the node, we stream the log records without committing them individually (thus we model group commit here)
auto logServiceStorageWriteVolume = Rate::secondly((logNode.instanceStorage.getWriteThroughput() * logNodeFraction) / p.getLogRecordSize());
auto logServiceNetworkReads = logNode.network.getReadLimit() / p.getLogRecordSize() * logNodeFraction;
auto logServiceNetworkWrites = logNode.network.getWriteLimit() / p.getLogRecordSize() * logNodeFraction / targets;
auto logDeviceThroughput = Rate::secondly(logEBSDevice.bandwidth / p.getLogRecordSize());
auto result = vmin(logServiceStorageWriteVolume, logServiceNetworkReads, logServiceNetworkWrites, logDeviceThroughput);
if (!p.groupCommit) {
// On the log device, each commit is separate, thus we go for IOPS
auto logDeviceWriteOps = logEBSDevice.iops;
result = vmin(result, logDeviceWriteOps);
}
return result;
}
//--------------------------------------------------------------------------------