-
Notifications
You must be signed in to change notification settings - Fork 318
Expand file tree
/
Copy pathConfig.cpp
More file actions
272 lines (219 loc) · 8.75 KB
/
Config.cpp
File metadata and controls
272 lines (219 loc) · 8.75 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cachelib/cachebench/util/Config.h"
#include <folly/FileUtil.h>
#include <folly/json/json.h>
#include <unordered_map>
namespace facebook {
namespace cachelib {
namespace cachebench {
StressorConfig::StressorConfig(const folly::dynamic& configJson) {
JSONSetVal(configJson, generator);
JSONSetVal(configJson, name);
JSONSetVal(configJson, enableLookaside);
JSONSetVal(configJson, onlySetIfMiss);
JSONSetVal(configJson, ignoreOpCount);
JSONSetVal(configJson, populateItem);
JSONSetVal(configJson, samplingIntervalMs);
JSONSetVal(configJson, checkConsistency);
JSONSetVal(configJson, touchValue);
JSONSetVal(configJson, numOps);
JSONSetVal(configJson, numThreads);
JSONSetVal(configJson, numKeys);
JSONSetVal(configJson, opDelayBatch);
JSONSetVal(configJson, opDelayNs);
JSONSetVal(configJson, opRatePerSec);
JSONSetVal(configJson, opRateBurstSize);
JSONSetVal(configJson, opPoolDistribution);
JSONSetVal(configJson, keyPoolDistribution);
JSONSetVal(configJson, maxInconsistencyCount);
JSONSetVal(configJson, traceFileName);
JSONSetVal(configJson, traceFileNames);
JSONSetVal(configJson, configPath);
JSONSetVal(configJson, cachePieceSize);
JSONSetVal(configJson, maxCachePieces);
JSONSetVal(configJson, maxInvalidDestructorCount);
JSONSetVal(configJson, repeatTraceReplay);
JSONSetVal(configJson, timestampFactor);
JSONSetVal(configJson, checkNvmCacheWarmUp);
JSONSetVal(configJson, useCombinedLockForIterators);
JSONSetVal(configJson, useDTOAsync);
if (configJson.count("poolDistributions")) {
for (auto& it : configJson["poolDistributions"]) {
poolDistributions.emplace_back(it, configPath);
}
} else {
poolDistributions.emplace_back(configJson, configPath);
}
if (configJson.count("replayGeneratorConfig")) {
replayGeneratorConfig =
ReplayGeneratorConfig{configJson["replayGeneratorConfig"]};
}
if (configJson.count("nvmCacheWarmupCheckPolicy")) {
nvmCacheWarmupCheckPolicy =
WarmupCheckPolicy{configJson["nvmCacheWarmupCheckPolicy"]};
}
if (!traceFileName.empty() && !traceFileNames.empty()) {
throw std::invalid_argument(
folly::sformat("set only one of traceFileName or traceFileNames"));
}
// If you added new fields to the configuration, update the JSONSetVal
// to make them available for the json configs and increment the size
// below
checkCorrectSize<StressorConfig, 584>();
}
bool StressorConfig::usesChainedItems() const {
for (const auto& c : poolDistributions) {
if (c.usesChainedItems()) {
return true;
}
}
return false;
}
CacheBenchConfig::CacheBenchConfig(
const std::string& path,
const CacheConfigCustomizer& cacheConfigCustomizer,
const StressorConfigCustomizer& stressorConfigCustomizer) {
std::string configString;
if (!folly::readFile(path.c_str(), configString)) {
throw std::invalid_argument(
folly::sformat("could not read file: {}", path));
}
std::cout << "===JSON Config===" << std::endl;
std::cout << configString << std::endl;
auto configJson = folly::parseJson(folly::json::stripComments(configString));
auto& testConfigJson = configJson["test_config"];
if (testConfigJson.getDefault("configPath", "").empty()) {
// strip out the file name at the end to get the directory if the path
// contains / and if not, the path is present directory. Assume the file
// does not have any escaped '/'
auto pos = path.find_last_of('/');
const std::string configDir =
(pos != std::string::npos)
? std::string{path.begin(), path.begin() + pos}
: ".";
testConfigJson["configPath"] = configDir;
}
// if present, customize the configuration.
auto stressorConfig = StressorConfig{testConfigJson};
stressorConfig_ = stressorConfigCustomizer
? stressorConfigCustomizer(stressorConfig)
: stressorConfig;
if (configJson.count("cache_config")) {
auto cacheConfig = CacheConfig{configJson["cache_config"]};
cacheConfig_ = cacheConfigCustomizer ? cacheConfigCustomizer(cacheConfig)
: cacheConfig;
}
}
DistributionConfig::DistributionConfig(const folly::dynamic& jsonConfig,
const std::string& configPath) {
JSONSetVal(jsonConfig, keySizeRange);
JSONSetVal(jsonConfig, keySizeRangeProbability);
JSONSetVal(jsonConfig, valSizeRange);
JSONSetVal(jsonConfig, valSizeRangeProbability);
JSONSetVal(jsonConfig, valSizeDistFile);
JSONSetVal(jsonConfig, chainedItemLengthRange);
JSONSetVal(jsonConfig, chainedItemLengthRangeProbability);
JSONSetVal(jsonConfig, chainedItemValSizeRange);
JSONSetVal(jsonConfig, chainedItemValSizeRangeProbability);
JSONSetVal(jsonConfig, popularityBuckets);
JSONSetVal(jsonConfig, popularityWeights);
JSONSetVal(jsonConfig, popDistFile);
JSONSetVal(jsonConfig, getRatio);
JSONSetVal(jsonConfig, setRatio);
JSONSetVal(jsonConfig, delRatio);
JSONSetVal(jsonConfig, addChainedRatio);
JSONSetVal(jsonConfig, loneGetRatio);
JSONSetVal(jsonConfig, loneSetRatio);
JSONSetVal(jsonConfig, updateRatio);
JSONSetVal(jsonConfig, couldExistRatio);
JSONSetVal(jsonConfig, useLegacyKeyGen);
auto readFile = [&](const std::string& f) {
std::string str;
const std::string path = folly::sformat("{}/{}", configPath, f);
std::cout << "reading distribution params from " << path << std::endl;
if (!folly::readFile(path.c_str(), str)) {
throw std::invalid_argument(
folly::sformat("could not read file: {}", path));
}
return str;
};
if (!valSizeDistFile.empty()) {
const auto configJsonVal = folly::parseJson(readFile(valSizeDistFile));
JSONSetVal(configJsonVal, valSizeRange);
JSONSetVal(configJsonVal, valSizeRangeProbability);
}
if (!popDistFile.empty()) {
const auto configJsonPop = folly::parseJson(readFile(popDistFile));
JSONSetVal(configJsonPop, popularityBuckets);
JSONSetVal(configJsonPop, popularityWeights);
}
checkCorrectSize<DistributionConfig, 376>();
}
ReplayGeneratorConfig::ReplayGeneratorConfig(const folly::dynamic& configJson) {
JSONSetVal(configJson, ampFactor);
JSONSetVal(configJson, ampSizeFactor);
JSONSetVal(configJson, binaryFileName);
JSONSetVal(configJson, fastForwardCount);
JSONSetVal(configJson, preLoadReqs);
JSONSetVal(configJson, replaySerializationMode);
JSONSetVal(configJson, relaxedSerialIntervalMs);
JSONSetVal(configJson, numAggregationFields);
JSONSetVal(configJson, numExtraFields);
JSONSetVal(configJson, blockSizeKB);
JSONSetVal(configJson, chunkSizeKB);
JSONSetVal(configJson, statsPerAggField);
if (configJson.count("mlAdmissionConfig")) {
mlAdmissionConfig =
std::make_shared<MLAdmissionConfig>(configJson["mlAdmissionConfig"]);
}
if (replaySerializationMode != "strict" &&
replaySerializationMode != "relaxed" &&
replaySerializationMode != "none") {
throw std::invalid_argument(folly::sformat(
"Unsupported request serialization mode: {}", replaySerializationMode));
}
checkCorrectSize<ReplayGeneratorConfig, 184>();
}
ReplayGeneratorConfig::SerializeMode
ReplayGeneratorConfig::getSerializationMode() const {
if (replaySerializationMode == "relaxed") {
return ReplayGeneratorConfig::SerializeMode::relaxed;
}
if (replaySerializationMode == "none") {
return ReplayGeneratorConfig::SerializeMode::none;
}
return ReplayGeneratorConfig::SerializeMode::strict;
}
MLAdmissionConfig::MLAdmissionConfig(const folly::dynamic& configJson) {
JSONSetVal(configJson, modelPath);
JSONSetVal(configJson, numericFeatures);
JSONSetVal(configJson, categoricalFeatures);
JSONSetVal(configJson, targetRecall);
JSONSetVal(configJson, admitCategory);
checkCorrectSize<MLAdmissionConfig, 160>();
}
WarmupCheckPolicy::WarmupCheckPolicy(const folly::dynamic& configJson) {
// reset the default values to make sure they are not used
evictionCountThreshold = 0;
requestTimestampThreshold = 0;
JSONSetVal(configJson, evictionCountThreshold);
JSONSetVal(configJson, requestTimestampThreshold);
checkCorrectSize<WarmupCheckPolicy, 16>();
}
} // namespace cachebench
} // namespace cachelib
} // namespace facebook