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

PILOT-6724: add hard limit for queueing jobs into thread pool #199

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions app/configs/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Env:
greenroom_bucket_prefix = 'gr'
# the number of items to active interative mode
interative_threshold = 10
# set hard limit for pending jobs, otherwise cli will consume all memory
# to cache jobs. If later on the speed of chunk deliver become faster, we
# can increase the concurrency number.
num_of_jobs = 20

github_url = 'PilotDataPlatform/cli'

Expand Down
7 changes: 7 additions & 0 deletions app/services/file_manager/file_upload/upload_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import math
import os
import threading
import time
from logging import getLogger
from multiprocessing.pool import ApplyResult
Expand Down Expand Up @@ -302,6 +303,10 @@ def stream_upload(self, file_object: FileObject, pool: ThreadPool) -> List[Apply
been uploaded.
"""
count = 0
semaphore = threading.Semaphore(AppConfig.Env.num_of_jobs)

def on_complete(result):
semaphore.release()

# process on the file content
f = open(file_object.local_path, 'rb')
Expand All @@ -327,9 +332,11 @@ def stream_upload(self, file_object: FileObject, pool: ThreadPool) -> List[Apply
chunk_size = chunk_info.get('chunk_size', self.chunk_size)
file_object.update_progress(chunk_size)
else:
semaphore.acquire()
res = pool.apply_async(
self.upload_chunk,
args=(file_object, count + 1, chunk, local_chunk_etag, len(chunk)),
callback=on_complete,
)
chunk_result.append(res)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "app"
version = "3.11.0"
version = "3.12.0"
description = "This service is designed to support pilot platform"
authors = ["Indoc Systems"]

Expand Down
1 change: 0 additions & 1 deletion tests/app/commands/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_dataset_list_total_less_than_10(mocker, cli_runner):
question_mock = mocker.patch.object(questionary, 'select', return_value=questionary.select)

result = cli_runner.invoke(dataset_list, ['--page', 0, '--page-size', page_size])

assert result.exit_code == 0
assert '' == result.output
assert question_mock.call_count == 0
Expand Down
Loading