Skip to content

Commit

Permalink
Upload chunks in parallel
Browse files Browse the repository at this point in the history
fixes: pulp#263
  • Loading branch information
gerrod3 committed Aug 18, 2021
1 parent 94a7c9c commit be5f008
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/263.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Artifact chunks are now uploaded in parallel
10 changes: 7 additions & 3 deletions pulpcore/cli/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,24 @@ def upload(self, file: IO[bytes], chunk_size: int = 1000000) -> Any:
upload_href = upload_ctx.create(body={"size": size})["pulp_href"]

try:
tasks = []
while start < size:
end = min(size, start + chunk_size) - 1
file.seek(start)
chunk = file.read(chunk_size)
range_header = f"bytes {start}-{end}/{size}"
upload_ctx.update(
tasks.append(upload_ctx.update(
href=upload_href,
parameters={"Content-Range": range_header},
body={"sha256": hashlib.sha256(chunk).hexdigest()},
uploads={"file": chunk},
)
non_blocking=True,
))
start += chunk_size
click.echo(".", nl=False, err=True)

for task in tasks:
self.wait_for_task(task)
click.echo(".", nl=False, err=True)
click.echo("Upload complete. Creating artifact.", err=True)
task = upload_ctx.commit(
upload_href,
Expand Down

0 comments on commit be5f008

Please sign in to comment.