Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

[Experimental] Async downloads prototype - #1609

Closed
googlyrahman wants to merge 1 commit into
googleapis:mainfrom
googlyrahman:test
Closed

googlyrahman wants to merge 1 commit into
googleapis:mainfrom
googlyrahman:test

Conversation

@googlyrahman

Copy link
Copy Markdown
Contributor

The following changes are not meant for merge, as they are prototype-based to compare the performance of gcsfs with async python SDK.

@googlyrahman
googlyrahman requested review from a team November 12, 2025 19:09
@product-auto-label product-auto-label Bot added the size: l Pull request size is large. label Nov 12, 2025
@product-auto-label product-auto-label Bot added the api: storage Issues related to the googleapis/python-storage API. label Nov 12, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @googlyrahman, 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 introduces a prototype for an asynchronous client within the Google Cloud Storage SDK, primarily to explore and compare the performance of async downloads against the existing gcsfs library. The changes lay the groundwork for non-blocking I/O operations, particularly for large file downloads, by implementing an experimental parallel download mechanism. This is a proof-of-concept and not intended for immediate merge.

Highlights

  • Asynchronous Client and Connection: Introduced new AsyncConnection and Client classes, along with ClientWithProjectAsync, to establish an asynchronous infrastructure for Google Cloud Storage operations, including handling async credentials and mTLS endpoint selection.
  • Experimental Parallel Downloads: Implemented an experimental 'sliced download' mechanism within the AsyncClient that enables parallel downloading of large files (objects 1GB or larger) by dividing them into multiple chunks and fetching them concurrently using asyncio.gather. This feature is currently active when checksum validation is not 'md5'.
  • Asynchronous Download Stream Handling: Added DownloadAsync to manage the asynchronous reading and writing of download streams, utilizing aiohttp for non-blocking network requests and providing specific logic for checksum validation based on whether the download is sequential or parallel.
  • Client Option and Endpoint Management: Enhanced the client initialization to support various client options, including API key, universe domain, and overrides for storage emulator or API endpoints, ensuring proper configuration for asynchronous operations.
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. ↩

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

Copy link
Copy Markdown
Contributor

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 an experimental prototype for asynchronous downloads, including a sliced download strategy for large files. The implementation is a solid starting point. My review focuses on improving code clarity and maintainability by addressing magic numbers, suggesting a more readable approach for chunk calculations, and noting debug print statements that should be replaced with proper logging in a production environment.

await download_obj.consume(transport, timeout=timeout)

def _check_if_sliced_download_is_eligible(self, obj_size, checksum):
if obj_size < 1024*1024*1024:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The file size threshold 1024*1024*1024 (1 GiB) is a magic number. Consider defining it as a module-level constant (e.g., _SLICED_DOWNLOAD_THRESHOLD_BYTES) to improve readability and maintainability.

obj_size = blob_obj.size
try:
if not sequential_read and self._check_if_sliced_download_is_eligible(obj_size, checksum): # 1GB
print("Sliced Download Preferred, and Starting...")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This print statement appears to be for debugging. In a production-ready version of this code, it should be replaced with a proper logging call, for instance, using Python's logging module.

Comment on lines +231 to +233
chunks_offset = [0] + [obj_size//_parts]*(_parts-1) + [obj_size - obj_size//_parts*(_parts-1)]
for i in range(1, _parts+1):
chunks_offset[i]+=chunks_offset[i-1]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This logic for calculating chunk offsets can be simplified for better readability. A more direct approach would make the intent clearer.

Suggested change
chunks_offset = [0] + [obj_size//_parts]*(_parts-1) + [obj_size - obj_size//_parts*(_parts-1)]
for i in range(1, _parts+1):
chunks_offset[i]+=chunks_offset[i-1]
chunk_size = obj_size // _parts
chunks_offset = [i * chunk_size for i in range(_parts + 1)]
chunks_offset[-1] = obj_size

for file_handle in file_handles:
file_handle.close()
else:
print("Sequential Download Preferred, and Starting...")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This print statement appears to be for debugging. In a production-ready version of this code, it should be replaced with a proper logging call, for instance, using Python's logging module.

self._checksum_object = checksum_object

async with response:
chunk_size = 4096 * 32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The chunk size 4096 * 32 (128 KiB) is a magic number. Consider defining it as a module-level constant (e.g., _DOWNLOAD_CHUNK_SIZE) to improve readability and maintainability.

@googlyrahman
googlyrahman marked this pull request as draft November 12, 2025 19:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: storage Issues related to the googleapis/python-storage API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants