Skip to content

Commit 7c32678

Browse files
v1/topdown/graphql: Cache GraphQL schema parse results (open-policy-agent#5377)
This commit stores parsed GraphQL schemas to the cache, which improves the performance of GraphQL operations that parse the schema more than once. Queries are not cached. pkg: github.com/open-policy-agent/opa/v1/topdown cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkGraphQLSchemaIsValid/Trivial_Schema_-_string-16 15519 100178 ns/op BenchmarkGraphQLSchemaIsValid/Trivial_Schema_with_cache_-_string-16 371311 3383 ns/op BenchmarkGraphQLSchemaIsValid/Trivial_Schema_with_cache_-_AST_object-16 66594 18093 ns/op BenchmarkGraphQLParseSchema/Trivial_Schema_-_string-16 6429 173773 ns/op BenchmarkGraphQLParseSchema/Trivial_Schema_with_cache_-_string-16 6523 170819 ns/op BenchmarkGraphQLParseQuery/Trivial_Query_-_string-16 16352 72777 ns/op BenchmarkGraphQLParseQuery/Trivial_Query_with_cache_-_string-16 16083 73548 ns/op BenchmarkGraphQLIsValid/Trivial_Schema_-_string-16 14320 83589 ns/op BenchmarkGraphQLIsValid/Trivial_Schema_with_cache_-_string-16 71486 15463 ns/op BenchmarkGraphQLParse/Trivial_Schema_-_string-16 3380 321490 ns/op BenchmarkGraphQLParse/Trivial_Schema_with_cache_-_string-16 13909 87633 ns/op BenchmarkGraphQLParseAndVerify/Trivial_Schema_-_string-16 3435 327646 ns/op BenchmarkGraphQLParseAndVerify/Trivial_Schema_with_cache_-_string-16 13844 85213 ns/op PASS ok github.com/open-policy-agent/opa/v1/topdown 112.465s Resolves: open-policy-agent#5377 Signed-off-by: Rob Myers <[email protected]>
1 parent 2c12366 commit 7c32678

File tree

4 files changed

+1414
-93
lines changed

4 files changed

+1414
-93
lines changed

Diff for: docs/content/configuration.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -863,14 +863,15 @@ Caching represents the configuration of the inter-query cache that built-in func
863863
functions provided by OPA, `http.send` is currently the only one to utilize the inter-query cache. See the documentation
864864
on the [http.send built-in function](../policy-reference/#http) for information about the available caching options.
865865

866-
It also represents the configuration of the inter-query _value_ cache that built-in functions can utilize. Currently,
866+
It also represents the configuration of the inter-query _value_ cache that built-in functions can utilize. Currently,
867867
this cache is utilized by the `regex` and `glob` built-in functions for compiled regex and glob match patterns
868-
respectively, and the `json.schema_match` built-in function for compiled JSON schemas.
868+
respectively, the `json.schema_match` built-in function for compiled JSON schemas, and any `graphql` built-in function
869+
that requires GraphQL schemas.
869870

870871
| Field | Type | Required | Description |
871872
|--------------------------------------------------------------------------|---------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
872873
| `caching.inter_query_builtin_cache.max_size_bytes` | `int64` | No | Inter-query cache size limit in bytes. OPA will drop old items from the cache if this limit is exceeded. By default, no limit is set. |
873-
| `caching.inter_query_builtin_cache.forced_eviction_threshold_percentage` | `int64` | No | Threshold limit configured as percentage of `caching.inter_query_builtin_cache.max_size_bytes`, when exceeded OPA will start dropping old items permaturely. By default, set to `100`. |
874+
| `caching.inter_query_builtin_cache.forced_eviction_threshold_percentage` | `int64` | No | Threshold limit configured as percentage of `caching.inter_query_builtin_cache.max_size_bytes`, when exceeded OPA will start dropping old items prematurely. By default, set to `100`. |
874875
| `caching.inter_query_builtin_cache.stale_entry_eviction_period_seconds` | `int64` | No | Stale entry eviction period in seconds. OPA will drop expired items from the cache every `stale_entry_eviction_period_seconds`. By default, set to `0` indicating stale entry eviction is disabled. |
875876
| `caching.inter_query_builtin_value_cache.max_num_entries` | `int` | No | Maximum number of entries in the Inter-query value cache. OPA will drop random items from the cache if this limit is exceeded. By default, set to `0` indicating unlimited size. |
876877
| `caching.inter_query_builtin_value_cache.named.io_jwt.max_num_entries` | `int` | No | Maximum number of entries in the `io_jwt` cache, used by the [`io.jwt` token verification](../policy-reference/#tokens) built-in functions. OPA will drop random items from the cache if this limit is exceeded. By default, this cache is disabled. |

0 commit comments

Comments
 (0)