Skip to content

Conversation

@shubham-up-47
Copy link
Contributor

@shubham-up-47 shubham-up-47 commented Dec 10, 2025

This PR implements scalable multi-stream reading for Zonal Buckets by introducing a MultiStreamManager to pool and reuse gRPC connections. It mitigates performance regressions from frequent stream creation by reusing idle streams and load-balancing requests, while maintaining a proactive background connection to minimize latency during ramp-up.
Class UML diagrams of the final architecture: Link
Benchmarking script used: Link

Bechmarking the changes by reading 500 GB data (thread count = 1),

Bechmarking the changes by reading 500 GB data (thread count = 30),

Benchmarking by changing the MaximumRangeSizeOption values,

Code accurate Control flow diagram for this snippet,

auto async = MakeAsyncClient(project_id);
google::storage::v2::BidiReadObjectSpec spec; spec.set_bucket("projects/_/buckets/" + bucket); spec.set_object(object);
auto descriptor = *async.Open(spec).get();
auto [reader, token] = descriptor.Read(/*offset=*/0, /*limit=*/400 * 1024 * 1024);
for (auto t = std::move(token); t.valid(); ) { auto r = reader.Read(std::move(t)).get(); t = std::get<1>(*r); /* process std::get<0>(*r) */ }

@shubham-up-47 shubham-up-47 requested review from a team as code owners December 10, 2025 10:02
@shubham-up-47 shubham-up-47 marked this pull request as draft December 10, 2025 10:02
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Dec 10, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @shubham-up-47, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the asynchronous object download capabilities of the Google Cloud Storage C++ client. It introduces a dedicated MultiStreamManager to efficiently handle multiple concurrent read streams, centralizing their lifecycle, reuse, and proactive creation. This refactoring of ObjectDescriptorImpl aims to improve performance and resource utilization for large object downloads by maintaining a dynamic pool of ready streams and intelligently managing their allocation.

Highlights

  • New MultiStreamManager: Introduced a new generic MultiStreamManager template class to centralize the logic for managing multiple asynchronous streams, including their creation, reuse, and lifecycle.
  • ObjectDescriptorImpl Refactoring: The ObjectDescriptorImpl has been significantly refactored to integrate and utilize the new MultiStreamManager, replacing its previous manual stream management with a more robust and scalable approach for handling concurrent read operations.
  • Proactive Stream Creation and Reuse: The system now proactively creates new streams in the background to ensure a ready pool for continuous large object reads. Additionally, idle streams are intelligently identified and moved to the back of a queue for reuse, optimizing resource utilization.
  • Multi-Stream Logic Activation: Previously commented-out code in object_descriptor.cc responsible for triggering subsequent stream creation when read limits are exceeded has been uncommented and activated, enabling the multi-stream behavior.
  • Comprehensive Test Coverage: New unit tests have been added for the MultiStreamManager itself, and existing tests for ObjectDescriptorImpl have been updated and expanded to thoroughly validate the new multi-stream integration and behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a MultiStreamManager for handling multiple concurrent streams in asynchronous downloads, a significant enhancement. The refactoring of ObjectDescriptorImpl to utilize this manager is substantial and well-executed, incorporating proactive stream creation and the reuse of idle streams to boost performance. The accompanying tests are thorough, covering a good range of stream management scenarios.

I've identified a few areas for improvement. There is a code structure issue with the definition of ReadStream that creates a layering violation and should be addressed by moving it to its own header. Additionally, some temporary developer comments and FIXMEs remain in the code and tests that need to be cleaned up. Some documentation for public methods in ObjectDescriptorImpl was also removed and should be restored. Addressing these points will improve the overall quality and maintainability of the code.

@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

❌ Patch coverage is 98.02632% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.96%. Comparing base (d6aff23) to head (91abbce).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...rage/internal/async/object_descriptor_impl_test.cc 97.74% 9 Missing ⚠️
...loud/storage/internal/async/multi_stream_manager.h 93.10% 4 Missing ⚠️
...d/storage/internal/async/object_descriptor_impl.cc 98.34% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15823      +/-   ##
==========================================
+ Coverage   92.95%   92.96%   +0.01%     
==========================================
  Files        2458     2460       +2     
  Lines      227589   228210     +621     
==========================================
+ Hits       211553   212155     +602     
- Misses      16036    16055      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shubham-up-47
Copy link
Contributor Author

/gcbrun

@shubham-up-47 shubham-up-47 marked this pull request as ready for review December 15, 2025 05:32
if (it->active_ranges.size() < min_ranges) {
best_it = it;
min_ranges = it->active_ranges.size();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the active_ranges.size() value is 1 but range itself is 10GB, and in second case active_ranges.size() value is 5 but all the ranges are under 1 MB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we cannot predict how fast a large file will download, counting the active requests is the standard and most reliable way to balance the load.

void Cancel() override {
if (stream_) stream_->Cancel();
}

Copy link
Member

Choose a reason for hiding this comment

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

Is there a private: missing here or are these member variables intended to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have switched ReadStream to a struct and made its fields public (no trailing underscores) per our style guide for structs. They stay public because MultiStreamManager mutates them directly on the hot path.

v-pratap
v-pratap previously approved these changes Dec 19, 2025
scotthart
scotthart previously approved these changes Dec 19, 2025
v-pratap
v-pratap previously approved these changes Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants