Skip to content

Commit

Permalink
feat(dask): set maximum limit for number of workers (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alputer committed Nov 5, 2024
1 parent 15d0b97 commit cdba3b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions reana_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
)
"""Number of workers in Dask cluster by default """

REANA_DASK_CLUSTER_MAX_NUMBER_OF_WORKERS = int(
os.getenv("REANA_DASK_CLUSTER_MAX_NUMBER_OF_WORKERS", 20)
)
"""Maximum number of workers in Dask cluster."""

REANA_DASK_CLUSTER_DEFAULT_SINGLE_WORKER_MEMORY = os.getenv(
"REANA_DASK_CLUSTER_DEFAULT_SINGLE_WORKER_MEMORY", "2Gi"
)
Expand Down
7 changes: 7 additions & 0 deletions reana_server/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DASK_ENABLED,
REANA_DASK_CLUSTER_MAX_MEMORY_LIMIT,
REANA_DASK_CLUSTER_DEFAULT_NUMBER_OF_WORKERS,
REANA_DASK_CLUSTER_MAX_NUMBER_OF_WORKERS,
REANA_DASK_CLUSTER_DEFAULT_SINGLE_WORKER_MEMORY,
REANA_DASK_CLUSTER_MAX_SINGLE_WORKER_MEMORY,
)
Expand Down Expand Up @@ -188,6 +189,12 @@ def validate_dask_memory_and_cores_limits(reana_yaml: Dict) -> None:
"number_of_workers", REANA_DASK_CLUSTER_DEFAULT_NUMBER_OF_WORKERS
)
)

if number_of_workers > REANA_DASK_CLUSTER_MAX_NUMBER_OF_WORKERS:
raise REANAValidationError(

Check warning on line 194 in reana_server/validation.py

View check run for this annotation

Codecov / codecov/patch

reana_server/validation.py#L193-L194

Added lines #L193 - L194 were not covered by tests
f'The "number_of_workers" provided in the dask resources exceeds the limit ({REANA_DASK_CLUSTER_MAX_NUMBER_OF_WORKERS}).'
)

requested_dask_cluster_memory = (
kubernetes_memory_to_bytes(single_worker_memory) * number_of_workers
)
Expand Down

0 comments on commit cdba3b1

Please sign in to comment.