Skip to content

Commit 8f456d9

Browse files
committed
add resource info on instance types as well
1 parent d8981c9 commit 8f456d9

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/_auto_scaling_core.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ async def _try_attach_pending_ec2s(
346346
)
347347

348348

349-
async def _sorted_allowed_instance_types(app: FastAPI) -> list[EC2InstanceType]:
349+
async def _sorted_allowed_instance_types(
350+
app: FastAPI, auto_scaling_mode: AutoscalingProvider
351+
) -> list[EC2InstanceType]:
350352
app_settings: ApplicationSettings = app.state.settings
351353
assert app_settings.AUTOSCALING_EC2_INSTANCES # nosec
352354
ec2_client = get_ec2_client(app)
@@ -370,6 +372,8 @@ def _as_selection(instance_type: EC2InstanceType) -> int:
370372
return allowed_instance_type_names.index(f"{instance_type.name}")
371373

372374
allowed_instance_types.sort(key=_as_selection)
375+
for instance_type in allowed_instance_types:
376+
auto_scaling_mode.add_instance_type_generic_resource(app, instance_type)
373377
return allowed_instance_types
374378

375379

@@ -1578,7 +1582,10 @@ async def auto_scale_cluster(
15781582
the additional load.
15791583
"""
15801584
# current state
1581-
allowed_instance_types = await _sorted_allowed_instance_types(app)
1585+
allowed_instance_types = await _sorted_allowed_instance_types(
1586+
app, auto_scaling_mode
1587+
)
1588+
15821589
cluster = await _analyze_current_cluster(
15831590
app, auto_scaling_mode, allowed_instance_types
15841591
)

services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/_provider_computational.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, cast
44

55
from aws_library.ec2 import EC2InstanceData, EC2Tags, Resources
6+
from aws_library.ec2._models import EC2InstanceType
67
from fastapi import FastAPI
78
from models_library.clusters import ClusterAuthentication
89
from models_library.docker import DockerLabelKey
@@ -191,3 +192,14 @@ def add_instance_generic_resources(
191192
app_settings = get_application_settings(app)
192193
assert app_settings.AUTOSCALING_DASK # nosec
193194
dask.add_instance_generic_resources(app_settings.AUTOSCALING_DASK, instance)
195+
196+
def add_instance_type_generic_resource(
197+
self, app: FastAPI, instance_type: EC2InstanceType
198+
) -> None:
199+
assert self # nosec
200+
assert app # nosec
201+
app_settings = get_application_settings(app)
202+
assert app_settings.AUTOSCALING_DASK # nosec
203+
dask.add_instance_type_generic_resource(
204+
app_settings.AUTOSCALING_DASK, instance_type
205+
)

services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/_provider_protocol.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Protocol
22

33
from aws_library.ec2 import EC2InstanceData, EC2Tags, Resources
4+
from aws_library.ec2._models import EC2InstanceType
45
from fastapi import FastAPI
56
from models_library.docker import DockerLabelKey
67
from models_library.generated_models.docker_rest_api import Node as DockerNode
@@ -51,3 +52,7 @@ async def try_retire_nodes(self, app: FastAPI) -> None: ...
5152
def add_instance_generic_resources(
5253
self, app: FastAPI, instance: EC2InstanceData
5354
) -> None: ...
55+
56+
def add_instance_type_generic_resource(
57+
self, app: FastAPI, instance_type: EC2InstanceType
58+
) -> None: ...

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import dask.typing
1010
import distributed
1111
from aws_library.ec2 import EC2InstanceData, Resources
12+
from aws_library.ec2._models import EC2InstanceType
1213
from dask_task_models_library.resource_constraints import (
1314
DASK_WORKER_THREAD_RESOURCE_NAME,
1415
DaskTaskResources,
@@ -359,3 +360,22 @@ def add_instance_generic_resources(
359360
instance.resources.generic_resources[
360361
create_ec2_resource_constraint_key(instance.type)
361362
] = _LARGE_RESOURCE
363+
364+
365+
def add_instance_type_generic_resource(
366+
settings: DaskMonitoringSettings, instance_type: EC2InstanceType
367+
) -> None:
368+
instance_threads = round(instance_type.resources.cpus)
369+
if settings.DASK_NTHREADS > 0:
370+
# this overrides everything
371+
instance_threads = settings.DASK_NTHREADS
372+
if settings.DASK_NTHREADS_MULTIPLIER > 1:
373+
instance_threads = instance_threads * settings.DASK_NTHREADS_MULTIPLIER
374+
375+
instance_type.resources.generic_resources[DASK_WORKER_THREAD_RESOURCE_NAME] = (
376+
instance_threads
377+
)
378+
379+
instance_type.resources.generic_resources[
380+
create_ec2_resource_constraint_key(instance_type.name)
381+
] = _LARGE_RESOURCE

0 commit comments

Comments
 (0)