Skip to content

Commit 0219413

Browse files
Jaesoo Leefacebook-github-bot
authored andcommitted
adding support for multiple trace files in test_config
Summary: This change adds the support for replaying the multiple trace files. The user can now specify multiple trace files to be replayed as an array 'traceFileNames' for the 'test_config'. Previous 'traceFileName' is also supported for backward compatibility, but only one of them can be specified. This change also adds the 'ignoreOpCount' option (default is false) which allows to ignore the op_count column and replay each operation only once. This change also performs several refactorings; (1) made the logic reading trace files reusable (i.e., new TraceFileStream class) and (2) deprecated AmplifiedReplayGenerator and made the ReplayGenerator supports both single and multi-threaded trace replays. Finally, this change implements a new unit test to test the parse logic. Reviewed By: jcipar Differential Revision: D41173006 fbshipit-source-id: 7630ad6dee6cbda2702b98cddb860ebf6d01b1fa
1 parent 2181e76 commit 0219413

File tree

9 files changed

+287
-197
lines changed

9 files changed

+287
-197
lines changed

cachelib/cachebench/runner/Stressor.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "cachelib/cachebench/runner/CacheStressor.h"
2222
#include "cachelib/cachebench/runner/FastShutdown.h"
2323
#include "cachelib/cachebench/runner/IntegrationStressor.h"
24-
#include "cachelib/cachebench/workload/AmplifiedReplayGenerator.h"
2524
#include "cachelib/cachebench/workload/OnlineGenerator.h"
2625
#include "cachelib/cachebench/workload/PieceWiseReplayGenerator.h"
2726
#include "cachelib/cachebench/workload/ReplayGenerator.h"
@@ -142,11 +141,7 @@ std::unique_ptr<GeneratorBase> makeGenerator(const StressorConfig& config) {
142141
if (config.generator == "piecewise-replay") {
143142
return std::make_unique<PieceWiseReplayGenerator>(config);
144143
} else if (config.generator == "replay") {
145-
if (config.numThreads > 1) {
146-
return std::make_unique<AmplifiedReplayGenerator>(config);
147-
} else {
148-
return std::make_unique<ReplayGenerator>(config);
149-
}
144+
return std::make_unique<ReplayGenerator>(config);
150145
} else if (config.generator.empty() || config.generator == "workload") {
151146
// TODO: Remove the empty() check once we label workload-based configs
152147
// properly

cachelib/cachebench/util/Config.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ StressorConfig::StressorConfig(const folly::dynamic& configJson) {
3131

3232
JSONSetVal(configJson, enableLookaside);
3333
JSONSetVal(configJson, onlySetIfMiss);
34+
JSONSetVal(configJson, ignoreOpCount);
3435
JSONSetVal(configJson, populateItem);
3536
JSONSetVal(configJson, samplingIntervalMs);
3637

@@ -53,6 +54,7 @@ StressorConfig::StressorConfig(const folly::dynamic& configJson) {
5354
JSONSetVal(configJson, maxInconsistencyCount);
5455

5556
JSONSetVal(configJson, traceFileName);
57+
JSONSetVal(configJson, traceFileNames);
5658
JSONSetVal(configJson, configPath);
5759

5860
JSONSetVal(configJson, cachePieceSize);
@@ -78,10 +80,15 @@ StressorConfig::StressorConfig(const folly::dynamic& configJson) {
7880
ReplayGeneratorConfig{configJson["replayGeneratorConfig"]};
7981
}
8082

83+
if (!traceFileName.empty() && !traceFileNames.empty()) {
84+
throw std::invalid_argument(
85+
folly::sformat("set only one of traceFileName or traceFileNames"));
86+
}
87+
8188
// If you added new fields to the configuration, update the JSONSetVal
8289
// to make them available for the json configs and increment the size
8390
// below
84-
checkCorrectSize<StressorConfig, 464>();
91+
checkCorrectSize<StressorConfig, 488>();
8592
}
8693

8794
bool StressorConfig::usesChainedItems() const {

cachelib/cachebench/util/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ struct StressorConfig : public JSONConfig {
181181
// follow get misses with a set
182182
bool enableLookaside{false};
183183

184+
// ignore opCount and does not repeat operations
185+
bool ignoreOpCount{false};
186+
184187
// only set a key in the cache if the key already doesn't exist
185188
// this is useful for replaying traces with both get and set, and also
186189
// for manually configured synthetic workloads.
@@ -233,6 +236,7 @@ struct StressorConfig : public JSONConfig {
233236
// Supported formats include specifying an absolute filename and filename
234237
// relative to the configPath
235238
std::string traceFileName{};
239+
std::vector<std::string> traceFileNames{};
236240

237241
// location of the path for the files referenced inside the json. If not
238242
// specified, it defaults to the path of the json file being parsed.

cachelib/cachebench/workload/AmplifiedReplayGenerator.h

Lines changed: 0 additions & 131 deletions
This file was deleted.

cachelib/cachebench/workload/PieceWiseReplayGenerator.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,9 @@ void PieceWiseReplayGenerator::getReqFromTrace() {
8080
auto totalFieldCount =
8181
partialFieldCount + config_.replayGeneratorConfig.numExtraFields;
8282
while (true) {
83-
if (!std::getline(infile_, line)) {
84-
if (repeatTraceReplay_) {
85-
XLOG_EVERY_MS(
86-
INFO, 100'000,
87-
"Reached the end of trace file. Restarting from beginning.");
88-
resetTraceFileToBeginning();
89-
continue;
90-
}
83+
try {
84+
traceStream_.getline(line);
85+
} catch (const cachelib::cachebench::EndOfTrace& e) {
9186
isEndOfFile_.store(true, std::memory_order_relaxed);
9287
break;
9388
}

cachelib/cachebench/workload/PieceWiseReplayGenerator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class PieceWiseReplayGenerator : public ReplayGeneratorBase {
3232
public:
3333
explicit PieceWiseReplayGenerator(const StressorConfig& config)
3434
: ReplayGeneratorBase(config),
35+
traceStream_(config, 0),
3536
pieceCacheAdapter_(config.maxCachePieces,
3637
config.replayGeneratorConfig.numAggregationFields,
3738
config.replayGeneratorConfig.statsPerAggField),
@@ -137,6 +138,8 @@ class PieceWiseReplayGenerator : public ReplayGeneratorBase {
137138
TOTAL_DEFINED_FIELDS = 11
138139
};
139140

141+
TraceFileStream traceStream_;
142+
140143
PieceWiseCacheAdapter pieceCacheAdapter_;
141144

142145
const ReplayGeneratorConfig::SerializeMode mode_{

0 commit comments

Comments
 (0)