Skip to main content

Scaling Runners

Scaling your runner groups is essential to handle varying workloads efficiently. This document explains how to use the StackGuardian Scaling API to manage scaling operations, allowing you to add or remove runners based on current demands.

Scaling with StackGuardian API

Manage the scaling of runner groups using the StackGuardian Scaling API. This allows you to scale out (add more runners) or scale in (remove runners) based on the workload.

Get Active Workflows

To get details about the workflows using a runner group, use the following API with the parameter getActiveWorkflows=true:

https://api.app.stackguardian.io/api/v1/orgs/<organization-name>/runnergroups/<runner-group-name>/?getActiveWorkflows=true

In the response, you will find the following keys describing the number of active workflows:

  • QueuedWorkflowsCount: Number of workflows queued and ready to run.
  • PendingWorkflowsCount: Number of workflows pending to be assigned to runners.
  • RunningWorkflowsCount: Number of workflows currently running.

Scaling Out

To determine if you need to scale out, sum the QueuedWorkflowsCount and PendingWorkflowsCount. If this sum is high, consider adding more runners to handle the load.

Example of Scaling Out:

{
"ContainerInstances": [
{
"containerInstanceArn": "exampleArn1",
"status": "ACTIVE",
"runningTasksCount": 1,
"pendingTasksCount": 2
},
{
"containerInstanceArn": "exampleArn2",
"status": "ACTIVE",
"runningTasksCount": 0,
"pendingTasksCount": 3
}
],
"QueuedWorkflowsCount": 0,
"PendingWorkflowsCount": 5,
"RunningWorkflowsCount": 1
}

Scaling In

To determine the number of workflows already in the running state, use RunningWorkflowsCount. To identify which runner in a runner group is running the workflows, use the ContainerInstances key in the response. This will be a list of objects containing details about the runners connected to the runner group.

Use the following keys within ContainerInstances to decide whether a runner should be shut down:

  • status: Indicates if the runner is ACTIVE or DRAINING.
  • runningTasksCount: Number of workflows currently running on the runner.
  • pendingTasksCount: Number of workflows pending on the runner.

If the RunningWorkflowsCount is low and certain runners have low runningTasksCount and pendingTasksCount, you can consider shutting down those runners.

Example of Scaling In

{
"ContainerInstances": [
{
"containerInstanceArn": "exampleArn",
"status": "ACTIVE",
"runningTasksCount": 0,
"pendingTasksCount": 0
}
]
}