Skip to content

Commit 63a432f

Browse files
igchorguptask
authored andcommitted
Extend cachbench with touch value
The main purpose of this patch is to better simulate workloads in cachebench. Setting touchValue to true allows to see performance impact of using different mediums for memory cache.
1 parent fc768e8 commit 63a432f

File tree

5 files changed

+18
-33
lines changed

5 files changed

+18
-33
lines changed

cachelib/cachebench/cache/Cache-inl.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,13 @@ template <typename Allocator>
312312
void Cache<Allocator>::enableConsistencyCheck(
313313
const std::vector<std::string>& keys) {
314314
XDCHECK(valueTracker_ == nullptr);
315-
XDCHECK(!valueValidatingEnabled());
316315
valueTracker_ =
317316
std::make_unique<ValueTracker>(ValueTracker::wrapStrings(keys));
318317
for (const std::string& key : keys) {
319318
invalidKeys_[key] = false;
320319
}
321320
}
322321

323-
template <typename Allocator>
324-
void Cache<Allocator>::enableValueValidating(
325-
const std::string &expectedValue) {
326-
XDCHECK(!valueValidatingEnabled());
327-
XDCHECK(!consistencyCheckEnabled());
328-
this->expectedValue_ = expectedValue;
329-
}
330-
331322
template <typename Allocator>
332323
typename Cache<Allocator>::RemoveRes Cache<Allocator>::remove(Key key) {
333324
if (!consistencyCheckEnabled()) {
@@ -421,17 +412,15 @@ typename Cache<Allocator>::WriteHandle Cache<Allocator>::insertOrReplace(
421412
}
422413

423414
template <typename Allocator>
424-
void Cache<Allocator>::validateValue(const ItemHandle &it) const {
425-
XDCHECK(valueValidatingEnabled());
426-
427-
const auto &expected = expectedValue_.value();
415+
void Cache<Allocator>::touchValue(const ItemHandle& it) const {
416+
XDCHECK(touchValueEnabled());
428417

429418
auto ptr = reinterpret_cast<const uint8_t*>(getMemory(it));
430-
auto cmp = std::memcmp(ptr, expected.data(), std::min<size_t>(expected.size(),
431-
getSize(it)));
432-
if (cmp != 0) {
433-
throw std::runtime_error("Value does not match!");
434-
}
419+
420+
/* The accumulate call is intended to access all bytes of the value
421+
* and nothing more. */
422+
auto sum = std::accumulate(ptr, ptr + getSize(it), 0ULL);
423+
folly::doNotOptimizeAway(sum);
435424
}
436425

437426
template <typename Allocator>
@@ -461,8 +450,6 @@ typename Cache<Allocator>::ItemHandle Cache<Allocator>::find(Key key,
461450
return it;
462451
}
463452

464-
XDCHECK(!valueValidatingEnabled());
465-
466453
auto opId = valueTracker_->beginGet(key);
467454
auto it = findFn();
468455
if (checkGet(opId, it)) {

cachelib/cachebench/cache/Cache.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ class Cache {
181181
return getSize(item.get());
182182
}
183183

184-
// checks if values stored in it matches expectedValue_.
185-
void validateValue(const ItemHandle &it) const;
184+
// read entire value on find.
185+
void touchValue(const ItemHandle& it) const;
186186

187187
// returns the size of the item, taking into account ItemRecords could be
188188
// enabled.
@@ -243,14 +243,11 @@ class Cache {
243243
// @param keys list of keys that the stressor uses for the workload.
244244
void enableConsistencyCheck(const std::vector<std::string>& keys);
245245

246-
// enables validating all values on find. Each value is compared to
247-
// expected Value.
248-
void enableValueValidating(const std::string &expectedValue);
249-
250246
// returns true if the consistency checking is enabled.
251247
bool consistencyCheckEnabled() const { return valueTracker_ != nullptr; }
252248

253-
bool valueValidatingEnabled() const { return expectedValue_.has_value(); }
249+
// returns true if touching value is enabled.
250+
bool touchValueEnabled() const { return touchValue_; }
254251

255252
// return true if the key was previously detected to be inconsistent. This
256253
// is useful only when consistency checking is enabled by calling
@@ -374,8 +371,8 @@ class Cache {
374371
// tracker for consistency monitoring.
375372
std::unique_ptr<ValueTracker> valueTracker_;
376373

377-
// exceptected value of all items in Cache.
378-
std::optional<std::string> expectedValue_;
374+
// read entire value on find.
375+
bool touchValue_{false};
379376

380377
// reading of the nand bytes written for the benchmark if enabled.
381378
const uint64_t nandBytesBegin_{0};

cachelib/cachebench/runner/CacheStressor.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ class CacheStressor : public Stressor {
114114
if (config_.checkConsistency) {
115115
cache_->enableConsistencyCheck(wg_->getAllKeys());
116116
}
117-
if (config_.validateValue) {
118-
cache_->enableValueValidating(hardcodedString_);
119-
}
120117
if (config_.opRatePerSec > 0) {
121118
rateLimiter_ = std::make_unique<folly::BasicTokenBucket<>>(
122119
config_.opRatePerSec, config_.opRatePerSec);

cachelib/cachebench/util/Config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ StressorConfig::StressorConfig(const folly::dynamic& configJson) {
3434
JSONSetVal(configJson, samplingIntervalMs);
3535

3636
JSONSetVal(configJson, checkConsistency);
37-
JSONSetVal(configJson, validateValue);
37+
JSONSetVal(configJson, touchValue);
3838

3939
JSONSetVal(configJson, numOps);
4040
JSONSetVal(configJson, numThreads);

cachelib/cachebench/util/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ struct StressorConfig : public JSONConfig {
195195
// Mutually exclusive with checkConsistency
196196
bool validateValue{false};
197197

198+
// If enabled, each value will be read on find. This is useful for measuring
199+
// performance of value access.
200+
bool touchValue{false};
201+
198202
uint64_t numOps{0}; // operation per thread
199203
uint64_t numThreads{0}; // number of threads that will run
200204
uint64_t numKeys{0}; // number of keys that will be used

0 commit comments

Comments
 (0)