Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion cachelib/cachebench/cache/Cache-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ uint64_t Cache<Allocator>::fetchNandWrites() const {
template <typename Allocator>
Cache<Allocator>::Cache(const CacheConfig& config,
ChainedItemMovingSync movingSync,
std::string cacheDir)
std::string cacheDir,
bool touchValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can touchValue be part of the CacheConfig ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. I understand why it might not be a good idea to do that. We are really bending our back to add this code so that it fits under the place where find() api latency is measured and it is looking a bit convoluted. But that's fine for now.

: config_(config),
touchValue_(touchValue),
nandBytesBegin_{fetchNandWrites()},
itemRecords_(config_.enableItemDestructorCheck) {
constexpr size_t MB = 1024ULL * 1024ULL;
Expand Down Expand Up @@ -396,6 +398,18 @@ typename Cache<Allocator>::WriteHandle Cache<Allocator>::insertOrReplace(
return rv;
}

template <typename Allocator>
void Cache<Allocator>::touchValue(const ReadHandle& it) const {
XDCHECK(touchValueEnabled());

auto ptr = reinterpret_cast<const uint8_t*>(getMemory(it));

/* The accumulate call is intended to access all bytes of the value
* and nothing more. */
auto sum = std::accumulate(ptr, ptr + getSize(it), 0ULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave a comment here that accumulate is intended to access all bytes of the item and nothing more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

folly::doNotOptimizeAway(sum);
}

template <typename Allocator>
typename Cache<Allocator>::ReadHandle Cache<Allocator>::find(Key key) {
auto findFn = [&]() {
Expand All @@ -406,6 +420,11 @@ typename Cache<Allocator>::ReadHandle Cache<Allocator>::find(Key key) {
// find from cache and wait for the result to be ready.
auto it = cache_->find(key);
it.wait();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks different from

tracker = util::LatencyTracker(cacheFindLatency_);

Are you on a stale base commit for this PR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - rebased.

if (touchValueEnabled()) {
touchValue(it);
}

return it;
};

Expand All @@ -431,6 +450,11 @@ typename Cache<Allocator>::WriteHandle Cache<Allocator>::findToWrite(Key key) {
// find from cache and wait for the result to be ready.
auto it = cache_->findToWrite(key);
it.wait();

if (touchValueEnabled()) {
touchValue(it);
}

return it;
};

Expand Down
13 changes: 12 additions & 1 deletion cachelib/cachebench/cache/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ class Cache {
// cache.
// @param cacheDir optional directory for the cache to enable
// persistence across restarts.
// @param touchValue read entire value on find
explicit Cache(const CacheConfig& config,
ChainedItemMovingSync movingSync = {},
std::string cacheDir = "");
std::string cacheDir = "",
bool touchValue = false);

~Cache();

Expand Down Expand Up @@ -179,6 +181,9 @@ class Cache {
return getSize(item.get());
}

// read entire value on find.
void touchValue(const ReadHandle& it) const;

// returns the size of the item, taking into account ItemRecords could be
// enabled.
uint32_t getSize(const Item* item) const noexcept;
Expand Down Expand Up @@ -241,6 +246,9 @@ class Cache {
// returns true if the consistency checking is enabled.
bool consistencyCheckEnabled() const { return valueTracker_ != nullptr; }

// returns true if touching value is enabled.
bool touchValueEnabled() const { return touchValue_; }

// return true if the key was previously detected to be inconsistent. This
// is useful only when consistency checking is enabled by calling
// enableConsistencyCheck()
Expand Down Expand Up @@ -363,6 +371,9 @@ class Cache {
// tracker for consistency monitoring.
std::unique_ptr<ValueTracker> valueTracker_;

// read entire value on find.
bool touchValue_{false};

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

Expand Down
3 changes: 2 additions & 1 deletion cachelib/cachebench/runner/CacheStressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class CacheStressor : public Stressor {
cacheConfig.ticker = ticker_;
}

cache_ = std::make_unique<CacheT>(cacheConfig, movingSync);
cache_ = std::make_unique<CacheT>(cacheConfig, movingSync, "",
config_.touchValue);
if (config_.opPoolDistribution.size() > cache_->numPools()) {
throw std::invalid_argument(folly::sformat(
"more pools specified in the test than in the cache. "
Expand Down
1 change: 1 addition & 0 deletions cachelib/cachebench/util/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ StressorConfig::StressorConfig(const folly::dynamic& configJson) {
JSONSetVal(configJson, samplingIntervalMs);

JSONSetVal(configJson, checkConsistency);
JSONSetVal(configJson, touchValue);

JSONSetVal(configJson, numOps);
JSONSetVal(configJson, numThreads);
Expand Down
4 changes: 4 additions & 0 deletions cachelib/cachebench/util/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ struct StressorConfig : public JSONConfig {
// output stats after warmup.
bool checkNvmCacheWarmUp{false};

// If enabled, each value will be read on find. This is useful for measuring
// performance of value access.
bool touchValue{false};

uint64_t numOps{0}; // operation per thread
uint64_t numThreads{0}; // number of threads that will run
uint64_t numKeys{0}; // number of keys that will be used
Expand Down