Skip to content

Commit

Permalink
fix(api-launcher-load): correct the launcher load to be in range [0, …
Browse files Browse the repository at this point in the history
…100] for local machine
  • Loading branch information
laurent-laporte-pro committed Mar 4, 2024
1 parent 540e0ba commit e0e4af4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion antarest/launcher/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions tests/launcher/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down

0 comments on commit e0e4af4

Please sign in to comment.