Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache simulator: Add a ghost cache for admission control and a hybrid row-block cache. #5534

Closed

Conversation

HaoyuHuang
Copy link
Contributor

@HaoyuHuang HaoyuHuang commented Jul 2, 2019

This PR adds a ghost cache for admission control. Specifically, it admits an entry on its second access.
It also adds a hybrid row-block cache that caches the referenced key-value pairs of a Get/MultiGet request instead of its blocks.

Test plan: make clean && COMPILE_WITH_ASAN=1 make check -j32

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@HaoyuHuang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@HaoyuHuang HaoyuHuang added the WIP Work in progress label Jul 8, 2019
@facebook-github-bot
Copy link
Contributor

@HaoyuHuang has updated the pull request. Re-import the pull request

@HaoyuHuang HaoyuHuang removed the WIP Work in progress label Jul 8, 2019
@HaoyuHuang HaoyuHuang changed the title Cache simulator: Add a ghost cache for admission control. Cache simulator: Add a ghost cache for admission control and a hybrid row-block cache. Jul 8, 2019
@facebook-github-bot
Copy link
Contributor

@HaoyuHuang has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@HaoyuHuang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@riversand963 riversand963 left a comment

Choose a reason for hiding this comment

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

Took a pass and left a few comments.

@@ -50,24 +181,48 @@ BlockCacheTraceSimulator::BlockCacheTraceSimulator(
cache_configurations_(cache_configurations) {}

Status BlockCacheTraceSimulator::InitializeCaches() {
const std::string ghost_cache_prefix = "ghost_";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth renaming to kGhostCachePrefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I renamed it.

utilities/simulator_cache/cache_simulator.h Show resolved Hide resolved
uint64_t accesses = hits + misses;
return static_cast<double>(misses * 100.0 / accesses);
void PrioritizedCacheSimulator::Access(const BlockCacheTraceRecord& access) {
bool is_cache_miss;
Copy link
Contributor

Choose a reason for hiding this comment

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

NIt: initialize to avoid linter warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initialized.

utilities/simulator_cache/cache_simulator.h Show resolved Hide resolved
user_accesses_ = 0;
user_misses_ = 0;
}
double miss_ratio() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added const for all functions that do not update member variables.

}
return static_cast<double>(num_misses_ * 100.0 / num_accesses_);
}
uint64_t total_accesses() { return num_accesses_; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added const for all functions that do not update member variables.

}
uint64_t total_accesses() { return num_accesses_; }

double user_miss_ratio() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added const for all functions that do not update member variables.

}
return static_cast<double>(user_misses_ * 100.0 / user_accesses_);
}
uint64_t user_accesses() { return user_accesses_; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added const for all functions that do not update member variables.

bool is_user_access, bool* is_cache_miss, bool* admitted,
bool update_metrics);

Cache::Priority ComputeBlockPriority(const BlockCacheTraceRecord& access);
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added const for all functions that do not update member variables.

const uint64_t kGhostCacheSize = 1024 * 1024;
} // namespace

class CacheSimulatorTest : public DBTestBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the base class does not have to be DBTestBase since many of its database operations, e.g. Open, Close, Put, Flush, etc. are not needed. Maybe consider use testing::Test or testing::WithParamInterface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I changed to testing::Test.

@facebook-github-bot
Copy link
Contributor

@HaoyuHuang has updated the pull request. Re-import the pull request

Copy link
Contributor

@riversand963 riversand963 left a comment

Choose a reason for hiding this comment

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

LGTM with a few comments.

@@ -1321,7 +1321,7 @@ backupable_db_test: utilities/backupable/backupable_db_test.o $(LIBOBJECTS) $(TE
checkpoint_test: utilities/checkpoint/checkpoint_test.o $(LIBOBJECTS) $(TESTHARNESS)
$(AM_LINK)

cache_simulator_test: utilities/simulator_cache/cache_simulator_test.o db/db_test_util.o $(LIBOBJECTS) $(TESTHARNESS)
cache_simulator_test: utilities/simulator_cache/cache_simulator_test.o $(LIBOBJECTS) $(TESTHARNESS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch. This can easily be forgotten.

};

// A map stores get_id to a map of row keys. For each row key, it stores a
// pair of booleans. The first bool is true when we observe a miss upon the
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it's not a pair of booleans. It's a boolean and an enum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the comment.

sim_cache_->Insert(access.block_key, /*value=*/nullptr, access.block_size,
/*deleter=*/nullptr, /*handle=*/nullptr);
if (handle != nullptr) {
sim_cache_->Release(handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remind me of why release the handle upon a hit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason is that each entry maintains a ref counter. It is incremented by one inside the lookup so we need to call Release to decrement the ref count.

@facebook-github-bot
Copy link
Contributor

@HaoyuHuang has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@HaoyuHuang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@HaoyuHuang merged this pull request in 1a59b6e.

merryChris pushed a commit to merryChris/rocksdb that referenced this pull request Nov 18, 2019
… row-block cache. (facebook#5534)

Summary:
This PR adds a ghost cache for admission control. Specifically, it admits an entry on its second access.
It also adds a hybrid row-block cache that caches the referenced key-value pairs of a Get/MultiGet request instead of its blocks.
Pull Request resolved: facebook#5534

Test Plan: make clean && COMPILE_WITH_ASAN=1 make check -j32

Differential Revision: D16101124

Pulled By: HaoyuHuang

fbshipit-source-id: b99edda6418a888e94eb40f71ece45d375e234b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants