drogonframework / drogonframework/drogon

CacheMap should use a RWlock

Open
#2,448 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
14.3k
Forks
1.4k
Avg merge
1d 12h
Merged PRs (30d)
15

Description

**Is your feature request related to a problem? Please describe.**

The current implementation of the CacheMap uses a plain `std::mutex` instead of a `std::shared_mutex`.

This means that even retrieving an entry can cause contention, this is not great for a cache assuming frequent reads and few writes! https://github.com/drogonframework/drogon/blob/3495522200664bfef150257157c30aa076188a79/lib/inc/drogon/CacheMap.h#L344

**Describe the solution you'd like**

Use a `std::shared_mutex` and avoid exclusive locks on read only paths.

**Describe alternatives you've considered**
I used to have my own cache based on a simple shared mutex with unordered_map and switched to drogon's as I thought it'd be optimized, observed worse performance.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.