Skip to content

Commit 4bb3107

Browse files
authored
Merge pull request #178 from AlmaLinux/feat-optimize-upload
Optimize Pulp upload: exponential backoff, reuse SHA256, fix size threshold
2 parents 54a9ad8 + aa4c053 commit 4bb3107

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

sign_node/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
DEFAULT_PULP_PASSWORD = "test_pwd"
2020
DEFAULT_PULP_CHUNK_SIZE = 8388608 # 8 MiB
2121
# Max file size to allow parallel upload for
22-
DEFAULT_PARALLEL_FILE_UPLOAD_SIZE = 52428800 # 500 MB
22+
DEFAULT_PARALLEL_FILE_UPLOAD_SIZE = 524288000 # 500 MB
2323
DEFAULT_PGP_PASSWORD = "test_pwd"
2424
DEFAULT_SENTRY_DSN = ""
2525
DEFAULT_SENTRY_ENVIRONMENT = "dev"

sign_node/uploaders/pulp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def _wait_for_task_completion(self, task_href: str) -> dict:
8888
8989
"""
9090
result = self._tasks_client.read(task_href)
91+
delay = 0.3
9192
while result.state not in ("failed", "completed"):
92-
time.sleep(5)
93+
time.sleep(delay)
94+
delay = min(delay * 2, 5)
9395
result = self._tasks_client.read(task_href)
9496
if result.state == "failed":
9597
raise TaskFailedError(f"task {task_href} has failed, " f"details: {result}")
@@ -113,25 +115,24 @@ def _create_upload(self, file_path: str) -> (str, int):
113115
response = self._uploads_client.create({"size": file_size})
114116
return response.pulp_href, file_size
115117

116-
def _commit_upload(self, file_path: str, reference: str) -> str:
118+
def _commit_upload(self, reference: str, file_sha256: str) -> str:
117119
"""
118120
Commits upload and waits until upload will be transformed to artifact.
119121
Returns artifact reference upon completion.
120122
121123
Parameters
122124
----------
123-
file_path : str
124-
Path to the file.
125125
reference : str
126126
Upload reference in Pulp.
127+
file_sha256 : str
128+
Pre-computed SHA256 of the file.
127129
128130
Returns
129131
-------
130132
str
131133
Reference to the created resource.
132134
133135
"""
134-
file_sha256 = hash_file(file_path, hash_type="sha256")
135136
response = self._uploads_client.commit(reference, {"sha256": file_sha256})
136137
task_result = self._wait_for_task_completion(response.task)
137138
return task_result.created_resources[0]
@@ -167,7 +168,7 @@ def _send_file(self, file_path: str) -> typing.Tuple[str, str]:
167168
self._uploads_client.update(
168169
f"bytes 0-{file_size - 1}/{file_size}", reference, file_path
169170
)
170-
artifact_href = self._commit_upload(file_path, reference)
171+
artifact_href = self._commit_upload(reference, file_sha256)
171172
return file_sha256, artifact_href
172173

173174
def check_if_artifact_exists(self, sha256: str) -> str:

0 commit comments

Comments
 (0)