Skip to content

Commit 3e9eca8

Browse files
committed
adjusted compute used resources
1 parent a9ee18e commit 3e9eca8

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

services/autoscaling/src/simcore_service_autoscaling/modules/dask.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,18 @@ def _list_processing_tasks_on_worker(
295295
total_resources_used.update(task_resources)
296296

297297
_logger.debug("found %s for %s", f"{total_resources_used=}", f"{worker_url=}")
298-
return Resources(
298+
worker_used_resources = Resources(
299299
cpus=total_resources_used.get("CPU", 0),
300300
ram=TypeAdapter(ByteSize).validate_python(
301301
total_resources_used.get("RAM", 0)
302302
),
303303
)
304+
if worker_processing_tasks:
305+
worker_used_resources.generic_resources[
306+
DASK_WORKER_THREAD_RESOURCE_NAME
307+
] = len(worker_processing_tasks)
308+
309+
return worker_used_resources
304310

305311

306312
async def compute_cluster_total_resources(
@@ -322,11 +328,17 @@ async def compute_cluster_total_resources(
322328
for worker_details in workers.values():
323329
if worker_details["host"] not in instance_host_resources_map:
324330
continue
325-
worker_ram = worker_details["memory_limit"]
331+
worker_dask_resources = worker_details["resources"]
326332
worker_threads = worker_details["nthreads"]
327333
cluster_resources += Resources(
328-
cpus=instance_host_resources_map[worker_details["host"]].cpus,
329-
ram=TypeAdapter(ByteSize).validate_python(worker_ram),
334+
cpus=worker_dask_resources.get(
335+
"CPU", instance_host_resources_map[worker_details["host"]].cpus
336+
),
337+
ram=TypeAdapter(ByteSize).validate_python(
338+
worker_dask_resources.get(
339+
"RAM", instance_host_resources_map[worker_details["host"]].ram
340+
)
341+
),
330342
generic_resources={DASK_WORKER_THREAD_RESOURCE_NAME: worker_threads},
331343
)
332344

services/autoscaling/tests/unit/test_modules_dask.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,11 @@ def _add_fct(x: int, y: int) -> int:
365365
await _wait_for_dask_scheduler_to_change_state()
366366
assert await get_worker_used_resources(
367367
scheduler_url, scheduler_authentication, fake_localhost_ec2_instance_data
368-
) == Resources(cpus=num_cpus, ram=ByteSize(0))
368+
) == Resources(
369+
cpus=num_cpus,
370+
ram=ByteSize(0),
371+
generic_resources={DASK_WORKER_THREAD_RESOURCE_NAME: 1},
372+
)
369373

370374
result = await future_queued_task.result(timeout=_DASK_SCHEDULER_REACTION_TIME_S) # type: ignore
371375
assert result == 7

0 commit comments

Comments
 (0)