experimental: Allow query plan & parsed/validated document cache config #3755
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces two experimental configuration options for existing internal cache stores:
experimental_approximateDocumentStoreSizeMiB
is added to theApolloServer
constructor options and controls the approximate[1] size, in MiB, of the request pipeline document store, which is used to avoid repeated parsing and validation passes on queries which equate to the samequeryHash
[2].experimental_approximateQueryPlanStoreMiB
is added to theApolloGateway
constructor options and controls the approximate[1] size of the query plan cache, which is used to avoid recalculation on repeated queries which equate to the samequeryHash
[2].These are currently experimental because a more flexible, zero-config approach could more effortlessly account for memory of various internal caches (e.g. these two caches together) and vary their sizes based based on available memory and the overall server performance, rather than needing hard-coded values which are less than precise and require experimentation and observability to set properly.
We have a number of internal cache stores right now that could benefit from such behavior:
I'm hoping some existing native object cache implementations may already exist as external libraries which we could rely on. I haven't been able to explore options yet, but such a library would be immensely useful to Apollo Server! For example, if a server where Apollo Server is running has 2GiB of free memory, it's a shame for us to not try to use it while it's available. Conversely, we have to be careful (as we are right now, out of respect for FaaS providers) about running with unbounded cache configurations on platforms where memory is constrainted.
Of course, the right solution will likely still allow manual configuration and limits, but a better zero-config option seems obtainable. If anyone is willing to explore and put together a proposal, please feel free to leave a comment or open an issue!
[1]: "Approximate", because it's based on the
JSON.stringify
'd byte-length of the value being cached.[2]: The
queryHash
is a SHA-256 value of the incoming operation.