diff --git a/packages/services/pegboard/src/workflows/datacenter.rs b/packages/services/pegboard/src/workflows/datacenter.rs index 0f0dd09567..9ff9e6ba82 100644 --- a/packages/services/pegboard/src/workflows/datacenter.rs +++ b/packages/services/pegboard/src/workflows/datacenter.rs @@ -124,7 +124,6 @@ async fn allocate_actor( "allocating actor" ); - // TODO(RVT-4455): Validate this isolate vs container logic // Even though isolates autoscale based on CPU, we allocate machines based on reservation in // balance proactively. Otherwise, we'd end up with bad scaling with retroactively choosing // nodes based on CPU load since actors will show the CPU load after a delay. @@ -173,23 +172,25 @@ async fn allocate_actor( SELECT $3, client_id, $4, $5 FROM available_clients WHERE - -- Containers: ensure has available resources - -- Isolates: don't limit resources for isolates since they scale on CPU - $8 = 1 OR - ( - allocated_cpu + $6 <= available_cpu AND - allocated_memory + $7 <= available_memory - ) - -- Container: binpack to the most-populated node to maximize density - -- Isolate: allocate to the least-allocated machine since we autoscale on CPU + -- Containers (0): ensure node has available resources + -- Isolates (1): don't limit resources since they scale on CPU + CASE WHEN $8 = 0 + THEN ( + allocated_cpu + $6 <= available_cpu AND + allocated_memory + $7 <= available_memory + ) + ELSE TRUE + END ORDER BY - CASE - WHEN $8 = 0 THEN -allocated_cpu - ELSE available_cpu - END ASC, - CASE - WHEN $8 = 0 THEN -allocated_memory - ELSE available_memory + -- Container (0): binpack to the most-populated node to maximize density + -- Isolate (1): allocate to the least-populated node since we autoscale on CPU + CASE WHEN $8 = 0 + THEN allocated_cpu + ELSE -allocated_cpu + END DESC, + CASE WHEN $8 = 0 + THEN allocated_memory + ELSE -allocated_memory END DESC LIMIT 1 RETURNING client_id