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

improvement(hashmap): use folly ConcurrentHashMap replace unordered_map #29

Merged
merged 4 commits into from
Nov 8, 2023

Conversation

Centurybbx
Copy link
Collaborator

  • 多线程改造:使用folly::ConcurrentHashMap来替换std::unordered_map
  • Work in progress...

@Centurybbx Centurybbx marked this pull request as draft November 4, 2023 13:41
@Centurybbx Centurybbx marked this pull request as ready for review November 7, 2023 03:59
@Centurybbx Centurybbx changed the title [WIP]improvement(hashmap): use folly ConcurrentHashMap replace unordered_map improvement(hashmap): use folly ConcurrentHashMap replace unordered_map Nov 7, 2023
clients.push_back(Clients::value_type(std::static_pointer_cast<PClient>(client->shared_from_this()), timeout, pos));
auto it = blockedClients_.find(key);
if (it != blockedClients_.end()) {
// since folly doesn't support modify value directly, we have to make a copy to update atomically
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里有没有并发安全问题?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

迭代器是一个不可变量;此外在官方的示例中,如果当前线程获取了某个迭代器,其余线程的更改对于当前线程是感知不到的,因此我认为是线程安全的

AlexStocks
AlexStocks previously approved these changes Nov 7, 2023
src/helper.h Outdated
}

it = container.cbegin();
size_t randomIdx = random() % container.size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里随机函数推荐使用 C++的随机函数, 像这里的

std::random_device rd;

这里我的锅, 在移植 pstd的时候, 没有把 随机函数 单独 包装好

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

src/store.cc Outdated
@@ -200,7 +210,7 @@ size_t PStore::BlockedClients::UnblockClient(PClient* client) {
const auto& keys = client->WaitingKeys();

for (const auto& key : keys) {
Clients& clients = blockedClients_[key];
Clients clients = blockedClients_[key];
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里用find会不会更好一点

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

嗯对,这里应该用find的

@AlexStocks AlexStocks merged commit b968704 into OpenAtomFoundation:unstable Nov 8, 2023
1 check passed
@Centurybbx Centurybbx deleted the folly-hashmap branch November 8, 2023 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants