Optimize backfill#854
Draft
cjonas9 wants to merge 13 commits into
Draft
Conversation
# Conflicts: # cmd/stellar-rpc/internal/integrationtest/infrastructure/perf-eval/backfill-test/runner/instantiate.go # cmd/stellar-rpc/internal/integrationtest/infrastructure/perf-eval/bootstrap-common.sh
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.
What
This PR introduces several experimental changes to backfill for the sake of drastically reducing its runtime (currently, we see its runtime decrease from ~7 hours -> <3 hours). These changes flatten the curve of ledger insertion time vs. count of ledgers inserted, a curve that grew explosive over the last ~6 months as ledger complexity increased. These changes are:
finalizecopies rows back into the canonical table and rebuilds the deferred tx + events indexes, then a final frontfill catches up ledgers that closed during the finalize phase (since it can take about an hour)Of these changes, the only "truly touches hot-ingest path" change is fixed-arity batching, but functionally, this introduces no behavioral differences. the only thing it changes is when within the transaction the INSERTs execute, not what the transaction commits. Before, each ledger's events were INSERTed immediately during ingestLedgerCloseMeta in variable-sized batches (≤1000 rows). We just fix the batch size so rows accumulate in the in-memory pending slice and are written by flushPending() at Commit (plus any full 3000-row batches along the way). This still commits the same rows in the same order in the same write txs.
Why
Backfill has demonstrated to have an explosive tail latency as ledgers are ingested into the DB due to the indexing overhead incurred by ever-compounding tx, event, and other inserts. It was never intended to take 7 hours in the first place, and this is a regression that's snuck up on us as ledger composition has grown more complex. Every chunk of 960 ledgers that we backfill now takes a constant time of ~45 seconds to insert, as opposed to exploding from ~40 seconds to ~5-6+ minutes by the end of a backfill.
This is strictly necessary if we wish to maintain architectural work done for the performance evaluation epic: GHA imposes a 6 hour cap on job length, and backfill takes way too long. Because we intend on using the DB backfilled in the backfill test (see PR #830) for the RPC stood up for the
stellar-rpc-blasterendpoint evaluation test, we must optimize backfill first -- these CI jobs are inherently serial.Known limitations
N/A