Skip to content
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

Performance: fetch range optimize #119

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ def _upload_chunk(self, final: bool = False) -> bool:

def _fetch_range(self, start: int, end: int) -> bytes:
if start == end:
logger.debug(
logger.warning(
"skip fetch for negative range - bucket=%s,key=%s,start=%d,end=%d",
self.bucket,
self.key,
Expand All @@ -2102,13 +2102,16 @@ def _fetch_range(self, start: int, end: int) -> bytes:
logger.debug("Fetch: %s/%s, %s-%s", self.bucket, self.key, start, end)

def fetch() -> bytes:
temp_buffer = io.BytesIO()
for chunk in self.fs.tos_client.get_object(
self.bucket, self.key, self.version_id, range_start=start, range_end=end
):
temp_buffer.write(chunk)
temp_buffer.seek(0)
return temp_buffer.read()
with io.BytesIO() as temp_buffer:
for chunk in self.fs.tos_client.get_object(
self.bucket,
self.key,
self.version_id,
range_start=start,
range_end=end,
):
temp_buffer.write(chunk)
return temp_buffer.getvalue()

return retryable_func_executor(fetch, max_retry_num=self.fs.max_retry_num)

Expand Down