-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix interquery cache memory leak #5488
Conversation
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
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.
This makes sense.I guess we won't need to do this https://sourcegraph.com/github.com/open-policy-agent/opa@7c052053899090af0d71007cfbd8ef1745289647/-/blob/topdown/cache/cache.go?L136 if we make the change in unsafeDelete
.
Thanks @philipaconrad, I've just done some simple tests to verify my hypothesis. I used a similar procedure to the one I wrote in "Steps to reproduce in this issue: #5359, using the following OPA policy:
I used a locust script to load test the policy using up to 1000 unique users (and I tested the following scenarios:
In scenario 1, OPA's memory usage would rise with the number of users until the In scenario 2, OPA's memory usage would rise continuously. The In scenario 3, OPA behaved just like scenario 1. In scenario 4, OPA behaved just like scenario 1, except I'm pretty confident this PR will fix the leak described in #5381 😄 I will follow up with some unit tests |
I updated the insert/update/delete tests to include check to ensure that the number of elements in Let me know if something else is required :) Removed WIP prefix from title. Pinging @ashutosh-narkar for review 🙂 |
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.
@asleire thanks for the fix. Changes lgtm.
67d5bc8
to
df1fa2a
Compare
7596b60
to
d2fb702
Compare
Signed-off-by: Aleksander <Alekken@live.no>
d2fb702
to
84461d7
Compare
I thought we could fix the leak in #5381 by keeping track of the elements in
c.l
and remove them from the list whenever the corresponding cache values are removed. Sincec.l
is already a doubly linked list it's possible to add this with very littlechanges and with O(1) complexity
I can add some tests if this looks otherwise OK