-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
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 |
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.16% 72.07% -0.09%
+ Complexity 65257 65214 -43
============================================
Files 5318 5318
Lines 303988 303993 +5
Branches 43987 43990 +3
============================================
- Hits 219358 219113 -245
- Misses 66674 66934 +260
+ Partials 17956 17946 -10 ☔ View full report in Codecov by Sentry. |
server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java
Outdated
Show resolved
Hide resolved
68e9bfc
to
7e3567f
Compare
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 <andrross@amazon.com>
7e3567f
to
6d353b6
Compare
❌ Gradle check result for 6d353b6: TIMEOUT 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? |
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.
I'm good with this, @reta? @shwetathareja?
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-16724-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 b1bf72f26e2681e4dbe726bc9605209675f6ab38
# Push it to GitHub
git push --set-upstream origin backport/backport-16724-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x Then, create a pull request where 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 no longer log deprecation warnings. I also added a check to skip the tracking if the deprecation logger is disabled. Signed-off-by: Andrew Ross <andrross@amazon.com> (cherry picked from commit b1bf72f)
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 no longer log deprecation warnings. I also added a check to skip the tracking if the deprecation logger is disabled. Signed-off-by: Andrew Ross <andrross@amazon.com> (cherry picked from commit b1bf72f) Signed-off-by: Andrew Ross <andrross@amazon.com>
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 no longer log deprecation warnings. I also added a check to skip the tracking if the deprecation logger is disabled. (cherry picked from commit b1bf72f) Signed-off-by: Andrew Ross <andrross@amazon.com>
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.