perf(google-drive): hand files to conversion round-robin by user

Merged
EV
1d ago
+125-6

Description

Stack B (quick wins in the Drive connector), B5. Plan section 1.1, "Interleave by user".

Base. The base is main (since 2026-11-12). The benchmark numbers below came from runs on top of #17548, which has the benchmark script.

Partitions list one after another, each as one user. Taken in order, every conversion in flight acts as that one user. Google's quotas are per user (the Docs API allows 300 reads a minute for each user), so the run meets one user's quota long before the project's.

_interleave_by_user reads up to 2,000 listed files ahead (DRIVE_INTERLEAVE_LOOKAHEAD) and yields them round-robin across their retriever users. _load_from_checkpoint wraps the listing in it.

Decisions

  • The checkpoint does not change. A connector call converts everything it lists before it returns. The order inside a call does not change what the checkpoint records.
  • Memory. The lookahead holds file metadata only, at most 2,000 files.
  • A user's own files keep their order.

How Has This Been Tested?

  • Unit tests in test_drive_conversion_batching.py: the files come in turn across users and reading stops at the lookahead (from #17542); every file comes once and a user's files keep their order (new). 225 pass with the other Drive unit tests.
  • Mock benchmark, default mock latency:
CorpusDocs per minute
240 files, mixed types#17548 (main)249
this PR271
520 files, more Google Docs#17548 (main)376
this PR368

This PR alone shows no gain on the mock. These runs had no rate-limited answer, and main converts on 8 threads, so no user came near a quota. The change matters with the rolling window of 32 workers (#17557) and a per-user limit. I did not measure the two together. #17542 measured them together on a live Workspace.

All runs: every file became a document, 0 failures, 0 duplicates.

  • ruff, ty, ods check-getattr, ods check-lazy-imports: pass.

Not run: a run with B1 and a tight Docs API quota, a live Workspace, the full pre-commit set and CI.

Docs

  • Customer-facing change: I updated documentation/ (text and screenshots).
  • No docs change needed (internal, tests, CI, or multi-tenant cloud only).

Credits

Dane (Danelegend) wrote this change in #17542.

Additional Options

  • [Optional] Please cherry-pick this PR to the latest release version.

Generated by Claude Code


Summary by cubic

Interleaves Google Drive file conversions across users so in-flight work stops concentrating on one user's Google quota at a time.

  • Reads up to 2,000 listed files ahead (DRIVE_INTERLEAVE_LOOKAHEAD) and hands them round-robin across their retriever users.
  • A user's own files keep their order, and the checkpoint format is unchanged.

[!NOTE]

Feed Google Drive files to conversion in round-robin order by user

  • Adds _interleave_by_user, an iterator that buffers up to DRIVE_INTERLEAVE_LOOKAHEAD (2000) files, groups them by retriever user, and yields them in round-robin user turns while preserving each user's file order
  • GoogleDriveConnector's checkpointed retrieval now wraps the _fetch_drive_items iterator with this interleaver before handing files to document conversion, in connector.py
  • Adds unit tests in test_drive_conversion_batching.py covering round-robin ordering, lookahead read-ahead, completeness, and per-user order preservation
  • Risk: conversion order changes from listing order to interleaved order; checkpoint semantics depend on the documented buffering behavior of _interleave_by_user

Macroscope summarized d70ad00.

Summary by CodeRabbit

  • Improvements
    • Google Drive sync now distributes file processing across users, while preserving each user’s file order. It uses a bounded lookahead and processes buffered files before finishing, helping prevent files from one user from delaying processing for others.