-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Slow http.send cache deserialization #3599
Comments
Hi @lukyer! Serializing cached items was a feature added quite recently. The reason for this is that storing the raw structs in memory has an overhead of something like ~20x compared to the size of the JSON serialized data. Each ~300KB item in your example would hence come with a memory overhead of about ~6MB. As you probably can imagine, this quickly adds up with an increasing number of distinct items, and we had many reports complaining about this. Possible improvements to help in your case could be to look into faster serialization, as suggested in #3254 , or perhaps allow for an option to decide whether to store cache entries serialized or not. |
@anderseknert thanks for quick reply and confirmation of this issue. I think it would be best to add |
@lukyer can you provide a bit more detail on your use case? E.g., how many distinct |
@tsandall the main idea is to load RBAC user-role-permission data in dynamic way (not just few static mappings). So basically the idea is to have memoized |
@lukyer okay, that's helpful. re: "the main idea is to load RBAC user-role-permission data in dynamic way (not just few static mappings)": Is this data global or per user? It sounds like these are the role definitions but I just want to check. For example, if you have two roles (reader and admin) and your app has permissions "write.widgets", "read.widgets", "manage.users" then the data would look something like:
Importantly, there's nothing user-specific in here so your policies are just making one distinct http.send calll. |
@tsandall |
@ashutosh-narkar this would be a good one for you to pickup. |
@lukyer that's fine. Thanks for explaining. @ashutosh-narkar if you don't have time to work on this, you could spec out how the solution would be implemented and perhaps someone else could pick it up. |
We can add a new request parameter to |
Moving this issue to planned. We should be able to get this into the next release (v0.31.0). |
This commit adds a new parameter to http.send to control how items are added to the inter-query cache. Currently two modes are supported which allow users to decide if they prefer cache memory conservation or low latency during cache lookups. Fixes open-policy-agent#3599 Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
This commit adds a new parameter to http.send to control how items are added to the inter-query cache. Currently two modes are supported which allow users to decide if they prefer cache memory conservation or low latency during cache lookups. Fixes #3599 Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
This commit adds a new parameter to http.send to control how items are added to the inter-query cache. Currently two modes are supported which allow users to decide if they prefer cache memory conservation or low latency during cache lookups. Fixes open-policy-agent#3599 Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com> Signed-off-by: Dolev Farhi <farhi.dolev@gmail.com>
Expected Behavior
http.send
application/json
body cache lookup is as fast as stored astext/plain
Actual Behavior
application/json
deserialization makes cache lookup much slowerSteps to Reproduce the Problem
OPA version 0.29.4, macos, run as standalone server
Additional Info
Hi all,
I am using
http.send
with caching. Caching works fine but the problem is that I'm loading bigger ~300 kB JSON file and it looks like the cache is storing serialized version (raw_body
) instead of AST (body
). Thus every cache lookup causes JSON deserialization which is way too slow for my usecase (~80ms instead of ~10ms when served astext/plain
).Is it possible to store in cache deserialized data instead of serialized one?
@ashutosh-narkar I think this
json.Unmarshall
might be causing those lags:ashutosh-narkar@445d79f#diff-4a137f284e9009d157ac4553842cb1c6e9260173fa29d3ed0d779f79e5b7a316R710
Or am I doing something completely wrong? Thanks for any ideas!
The text was updated successfully, but these errors were encountered: