-
Notifications
You must be signed in to change notification settings - Fork 420
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
[Performance] Avoid lock contention for getting count of inner dictionary size #2807
base: dev
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree company="Microsoft" |
@ms-ruochenyu Can you please open and link an issue to this? |
@@ -498,6 +511,7 @@ public bool SetValue(TKey key, TValue value, DateTime expirationTime) | |||
} | |||
|
|||
_map[key] = newCacheItem; | |||
Interlocked.Increment(ref _mapSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_map[key] = newCacheItem, does not imply the count has increased.
@ms-ruochenyu what is the performance gain? |
@brentschmaltz, below is a sample we collected in 1 of internal workload. The CPU cost was clustered to taking bucket write lock inside |
@ms-ruochenyu i am unable to understand your CPU diagram. |
@ms-ruochenyu - Please open a tracking issue for this. |
[Performance] Avoid lock contention for getting count of inner dictionary size
Summary of the changes (Less than 80 chars)
Avoid lock contention for getting count of inner dictionary size in EventBasedLRUCache.
Description
We have seen bottlenecks in some of internal cloud services where
EventBasedLRUCache<TKey, TValue>
calls Count() for its inner_map
. This property calculation brings with heavy lock contention, espeicial inSetValue()
andCompact()
This change adds a new private field
int this._mapSize
to be updated during entries in_map
being updated._mapSize
will be updated as atomic and only used to new cache size calculation so, there should not be beheavior change from observation outside.