From e0e4af4277d7e062cc2ad7f1d9ebc9dfbbbbd1d7 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Mon, 4 Mar 2024 21:11:47 +0100 Subject: [PATCH] fix(api-launcher-load): correct the launcher load to be in range [0, 100] for local machine --- antarest/launcher/service.py | 3 ++- tests/integration/test_integration.py | 4 ++-- tests/launcher/test_service.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/antarest/launcher/service.py b/antarest/launcher/service.py index 4c4ea9aa15..023296188b 100644 --- a/antarest/launcher/service.py +++ b/antarest/launcher/service.py @@ -657,7 +657,8 @@ def get_load(self) -> LauncherLoadDTO: for job in self.job_result_repository.get_running() ) - cluster_load_approx = min(1.0, local_used_cpus / (os.cpu_count() or 1)) + # The cluster load is approximated by the percentage of used CPUs. + cluster_load_approx = min(100.0, 100 * local_used_cpus / (os.cpu_count() or 1)) return LauncherLoadDTO( allocated_cpu_rate=cluster_load_approx, diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index ffa4d4a91d..8065039c92 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -299,8 +299,8 @@ def test_main(client: TestClient, admin_access_token: str, study_id: str) -> Non res = client.get("/v1/launcher/load", headers=admin_headers) assert res.status_code == 200, res.json() launcher_load = LauncherLoadDTO.parse_obj(res.json()) - assert launcher_load.allocated_cpu_rate == 1 / (os.cpu_count() or 1) - assert launcher_load.cluster_load_rate == 1 / (os.cpu_count() or 1) + assert launcher_load.allocated_cpu_rate == 100 / (os.cpu_count() or 1) + assert launcher_load.cluster_load_rate == 100 / (os.cpu_count() or 1) assert launcher_load.nb_queued_jobs == 0 assert launcher_load.launcher_status == "SUCCESS" diff --git a/tests/launcher/test_service.py b/tests/launcher/test_service.py index 72f95a782f..9095673070 100644 --- a/tests/launcher/test_service.py +++ b/tests/launcher/test_service.py @@ -937,8 +937,8 @@ def test_save_solver_stats(self, tmp_path: Path) -> None: ), ], { - "allocated_cpu_rate": min(1.0, 8.0 / (os.cpu_count() or 1)), - "cluster_load_rate": min(1.0, 8.0 / (os.cpu_count() or 1)), + "allocated_cpu_rate": min(100.0, 800 / (os.cpu_count() or 1)), + "cluster_load_rate": min(100.0, 800 / (os.cpu_count() or 1)), "nb_queued_jobs": 0, "launcher_status": "SUCCESS", },