Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
createExecutoracceptscache.durable, and Cloud uses it to keep evaluated tool listings in each app's data supervisor. Self-host only passescache.memory. When a self-host server restarts, it loses every listing it has evaluated, and the first search loads every app Worker to evaluate them again. With about 20 apps, that first search took 12 s and about 10 s of CPU, and peak memory roughly doubled. Freed memory went back to workerd's allocator, so RSS stayed high for the life of the process. Over a few days of restarts and updates, this looked like a memory leak.This PR gives self-host a
DurableDeclarationsstore in its product database:7_evaluated_declarationsaddshosted_evaluated (app, key, at, until, json). The step only adds a table. The running server never reads it.get. Returns the row whileuntilis in the future. A failed read counts as a miss.set. Upserts the row and keeps the newerat. Results over 4 MiB are not stored, matching Cloud's size limit. A failed write logs a warning.forgettingwraps the memory cache. Whenchanged(app, at)runs, it also deletes that app's durable rows withat <= at. Without this, a removed or changed app would come back with a stale listing after a restart. TheDurableDeclarationscontract requires this behavior.Results can include text derived from credentials. They stay in the product database, which already holds the operator's encrypted account state. This follows the rule in the
DurableDeclarationsdoc comment.Measurements
I measured on
executor@2.0.0-beta.8with this change backported. The host is Docker on an ARM64 machine (8 cores) running a copy of a live install with about 20 apps. Values are container RSS and the duration of the firstsearchcall after a restart.Both runs use the same image, so the store's contents are the only difference between them. That image also ran PGlite with
shared_buffers=32MB, which lowers both memory figures by about the same amount. Run 1 starts with an emptyhosted_evaluatedtable, which matches today's behavior after any restart. Run 2 restarts the same container after run 1 filled the table.Verification on
v2v2. The changes werecache.durable, theeffect/sqlimport, and a migration step instead of a runtimecreate table.tsc --noEmit -p .reports no errors. I could not runbun run typecheckbecausetsc-rshas nolinux-arm64build.oxlintpasses.I did not run the e2e suites. I did not repeat the restart benchmark on
v2.Open questions
hostedProductMigrationsalso runs on Cloud, so Cloud gets an emptyhosted_evaluatedtable it never uses. If you prefer, I can move the step into a migration only self-host runs.forgettingdeletes rows in a fire-and-forget fiber, becauseDeclarationCache.changedis synchronous. If the server stops before that delete runs, a stale row can survive until itsuntil. The same window exists in memory today. The row'satguard keeps it from overwriting newer results.