Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Improve performance of MemoryCache by using ConcurrentDictionary rather than ReaderWriterLockSlim #242

@mikeharder

Description

@mikeharder

It may be possible to significantly improve the performance of MemoryCache by using ConcurrentDictionary rather than Dictionary protected by a ReaderWriterLockSlim. Under high load, there is contention acquiring the read lock from ReaderWriterLockSlim.

I created a quick prototype which shows significantly improved performance, though it may not be functionally correct in all scenarios.

Scenario MemoryCache Implementation RPS CPU
Plaintext N/A 1,167,369 100%
MemoryCachePlaintext ReaderWriterLockSlim 342,129 60%
MemoryCachePlaintext ConcurrentDictionary 802,076 100%

The remaining work is to improve and test the ConcurrentDictionary implementation to ensure it's correct under high load, has no race conditions, etc.

Prototype: https://github.com/aspnet/Caching/tree/mikeharder/concurrent-dictionary

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions