Merge "Bump the chunk_size to use CPU more efficiently"
This commit is contained in:
@@ -35,9 +35,9 @@ def download_image_stream(conn):
|
|||||||
with open("myimage.qcow2", "wb") as local_image:
|
with open("myimage.qcow2", "wb") as local_image:
|
||||||
response = conn.image.download_image(image, stream=True)
|
response = conn.image.download_image(image, stream=True)
|
||||||
|
|
||||||
# Read only 1024 bytes of memory at a time until
|
# Read only 1 MiB of memory at a time until
|
||||||
# all of the image data has been consumed.
|
# all of the image data has been consumed.
|
||||||
for chunk in response.iter_content(chunk_size=1024):
|
for chunk in response.iter_content(chunk_size=1024 * 1024):
|
||||||
# With each chunk, add it to the hash to be computed.
|
# With each chunk, add it to the hash to be computed.
|
||||||
md5.update(chunk)
|
md5.update(chunk)
|
||||||
|
|
||||||
|
@@ -121,7 +121,7 @@ class ImageCloudMixin:
|
|||||||
name_or_id,
|
name_or_id,
|
||||||
output_path=None,
|
output_path=None,
|
||||||
output_file=None,
|
output_file=None,
|
||||||
chunk_size=1024,
|
chunk_size=1024 * 1024,
|
||||||
):
|
):
|
||||||
"""Download an image by name or ID
|
"""Download an image by name or ID
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ class ImageCloudMixin:
|
|||||||
image data to. Only write() will be called on this object. Either
|
image data to. Only write() will be called on this object. Either
|
||||||
this or output_path must be specified
|
this or output_path must be specified
|
||||||
:param int chunk_size: size in bytes to read from the wire and buffer
|
:param int chunk_size: size in bytes to read from the wire and buffer
|
||||||
at one time. Defaults to 1024
|
at one time. Defaults to 1024 * 1024 = 1 MiB
|
||||||
:returns: When output_path and output_file are not given - the bytes
|
:returns: When output_path and output_file are not given - the bytes
|
||||||
comprising the given Image when stream is False, otherwise a
|
comprising the given Image when stream is False, otherwise a
|
||||||
:class:`requests.Response` instance. When output_path or
|
:class:`requests.Response` instance. When output_path or
|
||||||
|
@@ -25,7 +25,9 @@ def _verify_checksum(md5, checksum):
|
|||||||
|
|
||||||
|
|
||||||
class DownloadMixin:
|
class DownloadMixin:
|
||||||
def download(self, session, stream=False, output=None, chunk_size=1024):
|
def download(
|
||||||
|
self, session, stream=False, output=None, chunk_size=1024 * 1024
|
||||||
|
):
|
||||||
"""Download the data contained in an image"""
|
"""Download the data contained in an image"""
|
||||||
# TODO(briancurtin): This method should probably offload the get
|
# TODO(briancurtin): This method should probably offload the get
|
||||||
# operation into another thread or something of that nature.
|
# operation into another thread or something of that nature.
|
||||||
|
@@ -390,7 +390,7 @@ class Proxy(proxy.Proxy):
|
|||||||
image,
|
image,
|
||||||
stream=False,
|
stream=False,
|
||||||
output=None,
|
output=None,
|
||||||
chunk_size=1024,
|
chunk_size=1024 * 1024,
|
||||||
):
|
):
|
||||||
"""Download an image
|
"""Download an image
|
||||||
|
|
||||||
@@ -415,7 +415,7 @@ class Proxy(proxy.Proxy):
|
|||||||
When ``False``, return the entire contents of the response.
|
When ``False``, return the entire contents of the response.
|
||||||
:param output: Either a file object or a path to store data into.
|
:param output: Either a file object or a path to store data into.
|
||||||
:param int chunk_size: size in bytes to read from the wire and buffer
|
:param int chunk_size: size in bytes to read from the wire and buffer
|
||||||
at one time. Defaults to 1024
|
at one time. Defaults to 1024 * 1024 = 1 MiB
|
||||||
|
|
||||||
:returns: When output is not given - the bytes comprising the given
|
:returns: When output is not given - the bytes comprising the given
|
||||||
Image when stream is False, otherwise a :class:`requests.Response`
|
Image when stream is False, otherwise a :class:`requests.Response`
|
||||||
|
@@ -784,7 +784,7 @@ class Proxy(proxy.Proxy):
|
|||||||
*,
|
*,
|
||||||
stream=False,
|
stream=False,
|
||||||
output=None,
|
output=None,
|
||||||
chunk_size=1024,
|
chunk_size=1024 * 1024,
|
||||||
):
|
):
|
||||||
"""Download an image
|
"""Download an image
|
||||||
|
|
||||||
@@ -808,7 +808,7 @@ class Proxy(proxy.Proxy):
|
|||||||
When ``False``, return the entire contents of the response.
|
When ``False``, return the entire contents of the response.
|
||||||
:param output: Either a file object or a path to store data into.
|
:param output: Either a file object or a path to store data into.
|
||||||
:param int chunk_size: size in bytes to read from the wire and buffer
|
:param int chunk_size: size in bytes to read from the wire and buffer
|
||||||
at one time. Defaults to 1024
|
at one time. Defaults to 1024 * 1024 = 1 MiB
|
||||||
|
|
||||||
:returns: When output is not given - the bytes comprising the given
|
:returns: When output is not given - the bytes comprising the given
|
||||||
Image when stream is False, otherwise a :class:`requests.Response`
|
Image when stream is False, otherwise a :class:`requests.Response`
|
||||||
|
Reference in New Issue
Block a user