Fix collection modified exception which causes rare HTTP 500s #5830
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Had some free time so I wanted to fix some intermittent 500s related to getting download counts on an ID. This PR addresses #5779.
Things done:
ConcurrentDictionary
in CloudDownloadCountService instead ofDictionary
. This allows concurrent reads (via HTTP requests) and writes (via a background refresh every 15 minutes)StringComparer.OrdinalIgnoreCase
. This should reduce allocations (not measured though).Dictionary
.Performance analysis:
Dictionary
Refresh
Dictionary
TryGetDownloadCountForPackageRegistration
ConcurrentDictionary
Refresh
ConcurrentDictionary
TryGetDownloadCountForPackageRegistration
For
Refresh
, I copied thedownloads.v1.json
from PROD to my own storage account and ran gallery code from my dev box. 100 iterations. Every 10 iterations I would refresh from scratch.For
TryGetDownloadCountForPackageRegistration
, I ran all PROD IDs throughTryGetDownloadCountForPackageRegistration
, which 176,157 invocations of the method. 245 iterations. Every 49 iterations I re-initialized the server (newRefresh
).I thing the stability of
ConcurrentDictionary
is worth the minor performance decrease. We can consider an alternative approach if you guys think its worth it.