feat: implement AsyncMultiRangeDownloader with multiplexed bidi-gRPC … · googleapis/google-cloud-python@493df65 · GitHub
Skip to content

Commit 493df65

Browse files
authored
feat: implement AsyncMultiRangeDownloader with multiplexed bidi-gRPC stream support (#16528)
This PR implements **`AsyncMultiRangeDownloader`** with a new **`_StreamMultiplexer`**, enabling multiple concurrent range downloads to share a single bidirectional gRPC stream. ### Before vs. After | Feature | Before | After (This PR) | | :--- | :--- | :--- | | **Concurrency** | Sequential or multiple connections | Concurrent over **one** connection | | **Overhead** | High (multiple gRPC streams) | Low (multiplexed single stream) | | **Reliability** | Per-stream retry logic | Unified generation-gated reopening | ### How it works The system uses a background **`_StreamMultiplexer`** to manage the shared bidirectional stream: 1. **Requests**: Concurrent tasks send range requests (`BidiReadObjectRequest`) directly to the shared stream. 2. **Multiplexing**: A background **Recv Loop** listens for all responses. It uses the `read_id` in each response to route data to the correct task-specific `asyncio.Queue`. 3. **Error Handling**: If the stream breaks, a **generation-gated lock** ensures the stream is reopened only once. All active tasks receive a `_StreamError` and automatically retry using the new stream generation. --- **Key Changes:** - **`_StreamMultiplexer`**: Background receiver loop for routing responses. - **Generation-Gated Reopening**: Coordinates stream recovery across concurrent tasks. - **`AsyncMultiRangeDownloader` Integration**: Full support for concurrent `download_ranges` calls.
1 parent 33e4a6f commit 493df65

5 files changed

Lines changed: 1202 additions & 172 deletions

File tree

Lines changed: 207 additions & 0 deletions

0 commit comments

Comments
 (0)