Skip to content
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

perf: Disable round trip on write #245

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

maxsmythe
Copy link
Contributor

This disables the round-tripping of cached data between serialized/deserialized JSON when caching in OPA. This reduces the amount of time a lock is held on OPA's cache, which helps mitigate the lock contention mentioned in
open-policy-agent/gatekeeper#2060

Signed-off-by: Max Smythe smythe@google.com

@maxsmythe maxsmythe force-pushed the no-json-roundtrip branch 2 times, most recently from 17d4e48 to 7baf9ad Compare September 15, 2022 23:53
@sozercan
Copy link
Member

@maxsmythe looks like GK and unit tests are failing

This disables the round-tripping of cached data between
serialized/deserialized JSON when caching in OPA. This
reduces the amount of time a lock is held on OPA's cache, which
helps mitigate the lock contention mentioned in
open-policy-agent/gatekeeper#2060

Signed-off-by: Max Smythe <smythe@google.com>
@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2022

Codecov Report

Base: 50.22% // Head: 50.16% // Decreases project coverage by -0.05% ⚠️

Coverage data is based on head (1ed4a41) compared to base (2d1f39f).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #245      +/-   ##
==========================================
- Coverage   50.22%   50.16%   -0.06%     
==========================================
  Files          64       64              
  Lines        4255     4266      +11     
==========================================
+ Hits         2137     2140       +3     
- Misses       1879     1885       +6     
- Partials      239      241       +2     
Flag Coverage Δ
unittests 50.16% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...y-agent/frameworks/constraint/pkg/client/client.go 87.61% <0.00%> (-1.54%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@maxsmythe
Copy link
Contributor Author

Yeah, turns out RoundTrip had a different signature than I thought. Hopefully the newest change works.

@@ -18,7 +18,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/golang/glog v1.0.0
github.com/google/go-cmp v0.5.9
github.com/open-policy-agent/opa v0.42.2
github.com/open-policy-agent/opa v0.44.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bump also fixes few CVEs. yay!

@@ -415,7 +416,22 @@ func (c *Client) AddData(ctx context.Context, data interface{}) (*types.Response
}
}

err = c.driver.AddData(ctx, name, key, processedData)
// Round trip data to force untyped JSON, as drivers are not type-aware
bytes, err := json.Marshal(processedData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own knowledge, why does doing round trip here improves performance compare to in storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storage acquires a mutex, so a round trip there blocks all Rego evaluation. Round trips here can be done in parallel without blocking Rego evaluation.

TL;DR less CPU time spent with a mutex

Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants