Skip to content

Commit

Permalink
Change download chunk size and increase download resume attempts.
Browse files Browse the repository at this point in the history
Use buffering size as download chunk size in order to improve overall
google storage blobs download performance. Also increase default
download resume attempts to bypass the connection reset issue described
in #435 for most of the possible cases.
  • Loading branch information
tcibinan committed Jul 2, 2019
1 parent 094016d commit c32b0e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pipe-cli/src/utilities/storage/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from google.auth.transport.requests import AuthorizedSession
from google.cloud.storage import Client, Blob
from google.oauth2.credentials import Credentials
from google import resumable_media
from google.resumable_media import DataCorruption
from google.resumable_media.requests import Download

Expand Down Expand Up @@ -169,7 +170,7 @@ def _do_resumable_upload(self, client, stream, content_type, size, num_retries,

class _ProgressBlob(_ResumableDownloadProgressMixin, _UploadProgressMixin, Blob):
PROGRESS_CHUNK_SIZE = 5 * 1024 * 1024 # 5 MB
DEFAULT_RESUME_ATTEMPTS = 5
DEFAULT_RESUME_ATTEMPTS = 100

def __init__(self, size, progress_callback, attempts=DEFAULT_RESUME_ATTEMPTS, *args, **kwargs):
"""
Expand Down Expand Up @@ -490,12 +491,16 @@ def transfer(self, source_wrapper, destination_wrapper, path=None, relative_path

def _download_to_file(self, blob, destination_key):
try:
self._replace_default_download_chunk_size(self._buffering)
with open(destination_key, "wb", buffering=self._buffering) as file_obj:
blob.download_to_file(file_obj)
except DataCorruption:
os.remove(destination_key)
raise

def _replace_default_download_chunk_size(self, chunk_size):
resumable_media.requests.download._SINGLE_GET_CHUNK_SIZE = chunk_size


class GsUploadManager(GsManager, AbstractTransferManager):

Expand Down

0 comments on commit c32b0e5

Please sign in to comment.