Skip to content

feat(storage): Adding support of single shot download #1493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

shubham-up-47
Copy link
Contributor

Adding the support of single shot download using a boolean flag.

Some results using the script in the customer issue,

  • Download speed with single_shot_download=false (default value) = 123 MB / sec
  • Download speed with single_shot_download=true = 136 MB / sec
  • RawDownload speed with single_shot_download=false (default value) = 131 MB / sec
  • RawDownload speed with single_shot_download=true = 289 MB / sec

@shubham-up-47 shubham-up-47 requested review from a team as code owners June 19, 2025 14:18
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/python-storage API. labels Jun 19, 2025
@chandra-siri
Copy link
Contributor

@shubham-up-47 Please add unit tests.

if self._single_shot_download:
# This is useful for smaller files, or when the user wants to
# download the entire file in one go.
content = response.content
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a headsup : make sure this also works for objects with content-encoding:gzip and br

if self._single_shot_download:
# This is useful for smaller files, or when the user wants to
# download the entire file in one go.
content = response.content
Copy link
Contributor

Choose a reason for hiding this comment

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

response.content will not download the entire file at once.
see response.content code which internally calls iter_content with CONTENT_CHUNK_SIZE (10KiB) little more than _SINGLE_GET_CHUNK_SIZE (8KiB).

that's the reason you're seeing only marginal improvement in download speed, from 123 -> 136

I suggest using response.raw.stream, response.raw will be urlib3's response object.

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 googleapis/python-storage API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants