-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Bound the size of cache in deprecation logger #16724
base: main
Are you sure you want to change the base?
Bound the size of cache in deprecation logger #16724
Conversation
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.
Is not using a concurrent hash map a premature optimization? After all even at high volume of requests you’re not going to hit a lock often (concurrent maps are very fast and use atomic swaps as far as I remember).
server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java
Outdated
Show resolved
Hide resolved
❌ Gradle check result for 1913d2b: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
@dblock I don't think using the OpenSearch What alternative do you have in mind with a concurrent hash map? The choices I see are: (1) stop deduplicating when the map hits a certain capacity, or (2) track insertion order to know which ones to evict. I could maybe be convinced that option 1 is good enough, but option 2 is what I implemented using the existing Cache data structure. |
I would agree with @dblock here, the
|
@reta Agreed that Also the hashcode thing was to make the memory utilization deterministic as every entry is the same size (a boxed integer). I'm happy to change this to a limited-capacity concurrent set of strings if you think that is good enough. That solution is definitely simple and fast. |
server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java
Outdated
Show resolved
Hide resolved
Thanks @andrross , I would have expected us to use LRU semantics but |
server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java
Show resolved
Hide resolved
@reta Without expiration policies the |
The current implementation of the map used to de-duplicate deprecation log messages can grow without bound. This adds a simple fixed limit to the data structure tracking existing loggers. Once the limit is breached new loggers will not be deduplicated. I also added a check to skip the tracking if the deprecation logger is disabled. Signed-off-by: Andrew Ross <[email protected]>
1913d2b
to
68e9bfc
Compare
@reta I pushed a simple version that simply enforces a size limit in the map. Let me know what you think. I also removed the hashcode() change, which now means we don't really have control over the amount of memory used as the size of the keys are controlled by the caller. But in practice I think this map would be at under 10MB unless unreasonably large keys are used. |
@dblock I think you would like it ;-) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16724 +/- ##
============================================
- Coverage 72.51% 72.11% -0.41%
+ Complexity 65562 65173 -389
============================================
Files 5318 5318
Lines 303945 303948 +3
Branches 43976 43978 +2
============================================
- Hits 220413 219182 -1231
- Misses 65798 66803 +1005
- Partials 17734 17963 +229 ☔ View full report in Codecov by Sentry. |
The current implementation of the map used to de-duplicate deprecation log
messages can grow without bound. This adds a simple fixed limit to the data
structure tracking existing loggers. Once the limit is breached new loggers will
not be deduplicated. I also added a check to skip the tracking if the
deprecation logger is disabled.
Related Issues
Resolves #16702
Check List
API changes companion pull request created, if applicable.Public documentation issue/PR created, if applicable.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.