Scaling improvements to allow very large collection pushes and queries - #29
Merged
Conversation
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.
A large test corpus, ~3M records, 5.5 GB could not complete: four separate memory ceilings sat below it and the manifest arrived as a single ~360 MB JSON body.
Nothing in the push protocol changes for existing clients. The CLI, mirror-sync,
pushVersionare untouched and take the same paths they always did. Everything new is opt-in.Read paths
record_idandtypeare denormalized ontoversion_records, indexed(version_id, record_id)and(version_id, type, record_id). Record listing,?type=filtering and the diff/delta set operations no longer join throughrecord_objectsjust to order or filter. The added/removed queries now plan as a merge anti-join between two index-only scans where they were correlatedNOT EXISTSlookups.?since=deltas and/diffare keyset-paginated. A delta of any size can be walked to completion.truncatedis retained and now mirrorspagination.hasMore, so clients that treat a capped delta as "rebuild from scratch" keep working unchanged.typeCountsis stored on the version row at commit. Fixespagination.totalunder?type=(it reported the whole-version count — 112,747 where the real answer was 25,341) and removes the per-page-viewCOUNT(*) GROUP BYon the collection page.503+Retry-Afterrather than a 500.INSERT … SELECTinstead of round-tripping every row through the app.Push path
version_recordsserver-side. Commit memory is now flat in collection size — measured at ~745 MB throughout a 500k commit, where it previously climbed for the duration./recordsare not re-validated, and records inherited from the base version are only re-validated when the schema set changed.POST …/commit?async=truereturns202and builds the version in the background; pollGET …/negotiate/:sessionIduntilstatusiscommitted(withresult) orfailed(witherror). The version is invisible to readers until the finalize completes, and a finalize whose process dies is swept bytool:cleanupSessions.manifest_expectedinstead of sendingmanifest, then POST JSONL chunks to…/negotiate/:sessionId/manifest. Each response reports which records from that chunk are needed, so bodies can start flowing before the manifest is complete. Chunks are idempotent by hash. Inline manifests are capped at 500,000 entries (413above that).Correctness
The version hash is the protocol's content-address, shared with the CLI, so a streaming implementation that merely looks right is worthless. Pushing byte-identical content through the old and new commit paths produces byte-identical
hashandpublic_hashat 2k, 3k, 500k and 1M records, including:public_hashand identicalpublic_record_hashpopulation;strip_unknown_fields, where records are rehashed mid-walk — a narrowed-schema stripping push lands on exactly the hash of a clean push of already-narrow records;VersionHashStreamis additionally locked tocomputeVersionHashby unit tests covering the golden value, empty sets, duplicate hashes, JSON-escaping edge cases and 200 randomized rounds. 97 tests pass.Measured
Chunked negotiate peak is flat rather than linear: 303 MB at 100k, 469 MB at 500k, 381 MB at 1M.
Also
/dev/shmin both compose files. Docker's 64 MB default is too small for parallel query workers once tables are large — a parallel aggregate over 500k rows failed withcould not resize shared memory segment. This would have bitten the first large query in production regardless of this branch.APP_HEAP_MB,APP_MEMORY_LIMIT). Sized for a shared box: dev and prod are co-resident, so the defaults here are paid four times over.llms.txt,/protocol, the versions API reference, integration docs, the per-collection agent instructions, README and the OpenAPI descriptions.Not in this PR
Record bodies still live in Postgres (feature-scaling Phase 1).
version_recordsis now index-dominated at ~395 bytes of index per row, which makesbytea(32)hashes the highest-value remaining storage change.mirror-syncstill single-shots the manifest and silently truncates above 10,000 records — pre-existing, and now a ~10-line fix since the response carriespagination.