Skip to content

perf(entity-store): batch snapshot bulk upserts in entity maintainers - #498

Draft
gurevichdmitry wants to merge 1 commit into
mainfrom
batch-snapshot-bulk-upserts
Draft

gurevichdmitry wants to merge 1 commit into
mainfrom
batch-snapshot-bulk-upserts

Conversation

@gurevichdmitry

Copy link
Copy Markdown
Contributor

Problem

generate-entity-maintainers-data --quick is by far the slowest step when creating an Entity Analytics environment, and much slower on Serverless:

Run generate-entity-maintainers-data Entities
ESS ~17 min 13.5k
Serverless ~70-81 min 13.3k

The loop in generateEntityMaintainersData awaits one bulkUpsert per 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 (with refresh: false, as before) every SNAPSHOT_FLUSH_OPS (100k bulk entries, ~50k docs), plus a final flush after the loop. generateSnapshotBulkOps only uses the single entity's source and its updateDoc, so nothing in the loop depends on the earlier writes.

Testing

  • tsc, eslint and prettier pass.
  • Not yet run against a live project. I'll run it through the security-test-environments create workflow (elastic/security-test-environments#17) and add the timings here.

Questions for reviewers

  • Is there a reason the snapshot upsert was per entity?
  • Is a 100k-entry flush size reasonable for memory and bulk request size?

🤖 Generated with Claude Code

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant