Skip to content

Select least-loaded eligible node when creating containers#300

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/distribute-containers-across-nodes
Draft

Select least-loaded eligible node when creating containers#300
Copilot wants to merge 6 commits intomainfrom
copilot/distribute-containers-across-nodes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

Container creation previously selected the first node matching eligibility filters, which could concentrate workloads on one node. This change updates placement to select the eligible node with the fewest existing containers.

  • Placement strategy update

    • Keep existing eligibility filters (siteId, API access credentials, optional nvidiaAvailable).
    • Replace single-node lookup with least-load selection across all eligible nodes.
  • Load-aware node selection

    • Fetch eligible node IDs.
    • Aggregate container counts per eligible node.
    • Choose the node with the smallest container count.
    • Apply deterministic tie-break by lowest node ID.
  • Behavior preserved

    • Existing error paths remain unchanged when no eligible node exists (including NVIDIA-specific case).
const eligibleNodes = await Node.findAll({ where: nodeWhere, attributes: ['id'] });
const eligibleNodeIds = eligibleNodes.map(({ id }) => id);

const nodeContainerCounts = eligibleNodeIds.length === 0 ? [] : await Container.findAll({
  where: { nodeId: eligibleNodeIds },
  attributes: ['nodeId', [Sequelize.fn('COUNT', Sequelize.col('id')), 'containerCount']],
  group: ['nodeId'],
  raw: true
});

const countByNodeId = new Map(
  nodeContainerCounts.map(({ nodeId, containerCount }) => [Number(nodeId), Number(containerCount)])
);

const node = eligibleNodes.reduce((leastLoadedNode, candidateNode) => {
  const candidateCount = countByNodeId.get(candidateNode.id) || 0;
  if (!leastLoadedNode) return candidateNode;
  const leastLoadedCount = countByNodeId.get(leastLoadedNode.id) || 0;
  if (candidateCount < leastLoadedCount) return candidateNode;
  if (candidateCount === leastLoadedCount && candidateNode.id < leastLoadedNode.id) return candidateNode;
  return leastLoadedNode;
}, null);

Copilot AI linked an issue May 8, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix container distribution across multiple nodes Select least-loaded eligible node when creating containers May 8, 2026
Copilot AI requested a review from runleveldev May 8, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distribute containers across multiple nodes

2 participants