Skip to content

Batch database queries in RdePipeline - #3190

Merged
gbrodman merged 1 commit into
google:masterfrom
gbrodman:rdeBatches
Aug 15, 2026
Merged

Batch database queries in RdePipeline#3190
gbrodman merged 1 commit into
google:masterfrom
gbrodman:rdeBatches

Conversation

@gbrodman

@gbrodman gbrodman commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Currently, we process (repoId, revisionId) pairs for DomainHistory and HostHistory individually -- they may be farmed out to worker nodes in parallel, but each EppResource uses a separate transaction and a separate read, which doesn't scale well when there are lots of domains/hosts. So as a result, we should batch them up so we can load (by default) 500 per transaction at a time.

We don't want to batch-load the domains/hosts at the same time that we retrieve the most recent history entry for each type -- this would mean passing relatively large objects across pipeline steps. Instead, we keep passing the KV<String, Long> and batch retrievals.

Self-scan D.2 number 5


This change is Reviewable

@gbrodman
gbrodman force-pushed the rdeBatches branch 3 times, most recently from bba0ba9 to 541e340 Compare July 31, 2026 15:24
@gbrodman gbrodman added the kokoro:force-run Force a Kokoro build. label Jul 31, 2026
@domain-registry-eng domain-registry-eng removed the kokoro:force-run Force a Kokoro build. label Jul 31, 2026
@gbrodman
gbrodman force-pushed the rdeBatches branch 6 times, most recently from 03657b3 to 2995c7f Compare August 3, 2026 17:23
@gbrodman
gbrodman requested a review from CydeWeys August 3, 2026 19:03

@CydeWeys CydeWeys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+a:@weiminyu to have a look as well.

@CydeWeys made 1 comment.
Reviewable status: 0 of 3 files reviewed, all discussions resolved (waiting on weiminyu).

@CydeWeys CydeWeys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to require some seriously careful testing on sandbox.

@CydeWeys made 1 comment.
Reviewable status: 0 of 3 files reviewed, all discussions resolved (waiting on weiminyu).

@weiminyu weiminyu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weiminyu reviewed 3 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on gbrodman).

@gbrodman

Copy link
Copy Markdown
Collaborator Author

OK so I tested this on alpha a ton.

On alpha, the base repo actually fails to run at all because a toooooon of domains reference the same host -- so we'd try to load the host a million times. The only thing I added against the base repository when testing the baseline was the "Deduplicate referenced hosts for grouping" step, line 463 here.

This doesn't really appear to run any more quickly, at least on alpha. This could be because of the skew in alpha data, but more likely it's because batching means that we need to wait until a batch is ready before sending it off to the next step, versus in the old system we could just send each domain/host off immediately to the next step when it was done. This is still worth doing though, because it'll decrease the load on the database massively.

#3206 reduces the time of the initial query by a large chunk too, from like two minutes down to 30 seconds.

The RDE output for a given day is the same in the old version and this new version

@gbrodman

Copy link
Copy Markdown
Collaborator Author

going to make a few more changes + add more tests, no need to review yet

@gbrodman gbrodman added kokoro:force-run Force a Kokoro build. and removed kokoro:force-run Force a Kokoro build. labels Aug 11, 2026
@gbrodman gbrodman removed the kokoro:force-run Force a Kokoro build. label Aug 11, 2026
Currently, we process (repoId, revisionId) pairs for DomainHistory and
HostHistory individually -- they may be farmed out to worker nodes in
parallel, but each EppResource uses a separate transaction and a separate read,
which doesn't scale well when there are lots of domains/hosts. So as a
result, we should batch them up so we can load (by default) 500 per
transaction at a time.

We don't want to batch-load the domains/hosts at the same time that we
retrieve the most recent history entry for each type -- this would mean
passing relatively large objects across pipeline steps. Instead, we keep
passing the KV<String, Long> and batch retrievals.

This isn't necessarily much faster (due to having to wait on batching)
but there'll be less load on the DB.

Self-scan D.2 number 5
@gbrodman

Copy link
Copy Markdown
Collaborator Author

OK PTAL -- this looks like a lot of code but the main things it actually changes are

  1. de-dupes the hosts around line 468 so we don't slam a million copies of the same host through one hot key
  2. shards and batches history entry loads in the three places they're done (domains, hosts, domains+hosts for subordinate hosts)
  3. updates the initial SQL query to move the TLD check into the inner subquery, meaning we don't need to do the group by / compute modification times for non-real TLDs

@weiminyu weiminyu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weiminyu reviewed 4 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on gbrodman).

@gbrodman
gbrodman added this pull request to the merge queue Aug 14, 2026
@gbrodman
gbrodman removed this pull request from the merge queue due to a manual request Aug 14, 2026
@gbrodman
gbrodman added this pull request to the merge queue Aug 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Aug 15, 2026
@gbrodman
gbrodman added this pull request to the merge queue Aug 15, 2026
Merged via the queue into google:master with commit a8f01d5 Aug 15, 2026
16 checks passed
@gbrodman
gbrodman deleted the rdeBatches branch August 15, 2026 02:48
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.

4 participants