Repository navigation
perf(entity-store): batch snapshot bulk upserts in entity maintainers - #498
Draft
gurevichdmitry wants to merge 1 commit into
Draft
gurevichdmitry wants to merge 1 commit into
gurevichdmitry wants to merge 1 commit into
Conversation
generateEntityMaintainersData awaited one bulkUpsert per entity for the snapshot maintainer (~30 docs each), i.e. ~13k sequential requests for a quick run. Buffer the snapshot ops and flush them through chunkedBulkUpsert every SNAPSHOT_FLUSH_OPS entries instead. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Problem
generate-entity-maintainers-data --quickis by far the slowest step when creating an Entity Analytics environment, and much slower on Serverless:generate-entity-maintainers-dataThe loop in
generateEntityMaintainersDataawaits onebulkUpsertper entity for the snapshot maintainer (~30 docs each,SNAPSHOT_DAYS = 30), so a quick run makes ~13k sequential requests. That is ~0.07s per request on ESS and ~0.37s on Serverless. Everything after the loop is already batched (chunkedBulkUpsert) and finishes in about a minute.Change
Buffer the snapshot ops and flush them through
chunkedBulkUpsert(withrefresh: false, as before) everySNAPSHOT_FLUSH_OPS(100k bulk entries, ~50k docs), plus a final flush after the loop.generateSnapshotBulkOpsonly uses the single entity's source and itsupdateDoc, so nothing in the loop depends on the earlier writes.Testing
tsc, eslint and prettier pass.security-test-environmentscreate workflow (elastic/security-test-environments#17) and add the timings here.Questions for reviewers
🤖 Generated with Claude Code