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

Perf(common): optimize cache promotion and demotion #2949

Merged
Merged
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
24 changes: 5 additions & 19 deletions src/common/lru_cache.h
Original file line number Diff line number Diff line change
@@ -204,7 +204,7 @@ class LRUCache : public LRUCacheInterface<K, V> {
void Remove(const K &key) override;

/*
* @brief Get the first key that $value = value
* @brief Get the first key that $value = value from lru tail to head
*
* @param[in] value
* @param[out] key
@@ -429,10 +429,7 @@ void LRUCache<K, V, KeyTraits, ValueTraits>::RemoveLocked(const K &key) {
template <typename K, typename V, typename KeyTraits, typename ValueTraits>
void LRUCache<K, V, KeyTraits, ValueTraits>::MoveToFront(
const typename std::list<Item>::iterator &elem) {
Item duplica{elem->key, elem->value};
ll_.erase(elem);
ll_.push_front(duplica);
cache_[*(duplica.key)] = ll_.begin();
ll_.splice(ll_.begin(), ll_, elem);
}

template <typename K, typename V, typename KeyTraits, typename ValueTraits>
@@ -699,16 +696,8 @@ bool SglLRUCache<K, KeyTraits>::MoveBack(const K &key) {
if (iter == cache_.end()) {
return false;
}
// delete the old value
RemoveElement(iter->second);
Copy link
Contributor

Choose a reason for hiding this comment

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

This function also include some metrics code, maybe you should consider it?

// put new value at tail
ll_.push_back(key);
cache_[key] = --ll_.end();
size_++;
if (cacheMetrics_ != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why delete these lines?

cacheMetrics_->UpdateAddToCacheCount();
cacheMetrics_->UpdateAddToCacheBytes(KeyTraits::CountBytes(key));
}
// move key to list tail
ll_.splice(ll_.end(), ll_, iter->second);
return true;
}

@@ -806,10 +795,7 @@ void SglLRUCache<K, KeyTraits>::RemoveLocked(const K &key) {
template <typename K, typename KeyTraits>
void SglLRUCache<K, KeyTraits>::MoveToFront(
const typename std::list<K>::iterator &elem) {
K tmp = *elem;
ll_.erase(elem);
ll_.emplace_front(tmp);
cache_[tmp] = ll_.begin();
ll_.splice(ll_.begin(), ll_, elem);
}

template <typename K, typename KeyTraits>
5 changes: 5 additions & 0 deletions test/client/client_metric_test.cpp
Original file line number Diff line number Diff line change
@@ -383,5 +383,10 @@ TEST(MetricTest, MetricHelperTest) {
ASSERT_NO_THROW(MetricHelper::IncremSlowRequestNum(nullptr));
}

TEST(MetricTest, CollectMetricsTest) {
InterfaceMetric interface("curve_client", "test");
ASSERT_NO_THROW(CollectMetrics(&interface, 1, 1));
}

} // namespace client
} // namespace curve
3 changes: 3 additions & 0 deletions test/client/libcbd_ext4_test.cpp
Original file line number Diff line number Diff line change
@@ -166,6 +166,9 @@ TEST(TestLibcbdExt4, AioReadWriteTest) {

ret = cbd_lib_fini();
ASSERT_EQ(ret, 0);

ret = cbd_lib_filesize("no_exist_file");
ASSERT_EQ(ret, -1);
}

TEST(TestLibcbdExt4, IncreaseEpochTest) {
9 changes: 9 additions & 0 deletions test/client/libcurve_client_unittest.cpp
Original file line number Diff line number Diff line change
@@ -210,6 +210,15 @@ TEST_F(CurveClientTest, TestAioWrite) {
}
}

TEST_F(CurveClientTest, TestIncreaseEpoch) {
{
EXPECT_CALL(*mockFileClient_, IncreaseEpoch(_)).Times(0);

ASSERT_EQ(-LIBCURVE_ERROR::FAILED,
client_.IncreaseEpoch(kWrongFileName));
}
}

} // namespace client
} // namespace curve

1 change: 1 addition & 0 deletions test/client/mock/mock_file_client.h
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ class MockFileClient : public FileClient {
MOCK_METHOD4(ReOpen, int(const std::string&, const std::string&,
const UserInfo&, std::string*));
MOCK_METHOD3(Extend, int(const std::string&, const UserInfo&, uint64_t));
MOCK_METHOD1(IncreaseEpoch, int(const std::string &));
};

} // namespace client