Optimizing GitHub Actions: Addressing 'max-parallel' Workflow Queuing in Development Activities
In the fast-paced world of development activities, optimizing CI/CD workflows is crucial for efficiency and cost-effectiveness. A recent GitHub Community discussion (Discussion #209687) brought to light a significant challenge with GitHub Actions' max-parallel strategy for matrix jobs, where the behavior of workflow_job "queued" events can lead to substantial resource waste and impact software project metrics.
The Challenge: Premature Queuing and Resource Waste
The core issue, as detailed by user andrewdibiasio6, revolves around how GitHub Actions handles matrix jobs when strategy.max-parallel is set to limit concurrent executions. Instead of queuing jobs sequentially as they become eligible, GitHub creates all matrix jobs at the start of a run and immediately dispatches a workflow_job event with action: queued for each of them. This happens even if max-parallel: 1 means only one job can truly run at a time.
This behavior has direct implications for autoscalers, such as those using the terraform-aws-github-runner module or webhook-driven Actions Runner Controller. These systems typically react to each queued event by launching a new runner. Consequently, if a matrix has eight jobs with max-parallel: 1, eight runners are launched almost simultaneously, even though seven of them will sit idle, waiting for the preceding jobs to complete. The discussion author observed that half of these pre-launched runners never executed a job, idling past their timeout and being terminated, representing a clear waste of resources and negatively affecting software project metrics related to infrastructure costs.
A critical missing piece of information is that the event payload does not indicate whether a job is truly waiting for runner capacity or merely blocked by max-parallel. This ambiguity prevents autoscalers from making intelligent provisioning decisions, leading to inflated "queue times" that primarily reflect the execution of earlier matrix cells rather than actual runner unavailability.
The Reusable Workflow Anomaly: A Glimmer of Efficiency
Intriguingly, the discussion highlights a stark contrast in behavior when a matrix job calls a reusable workflow instead of directly having runs-on. In this scenario, with the same max-parallel: 1 and eight cells, jobs are not all created and queued upfront. Instead, only the first cell exists initially, generating a single queued event and launching one runner. Subsequent cells are created and queued only after the previous one completes.
This difference in how GitHub Actions handles these two common development activity examples—direct matrix jobs versus matrix jobs using reusable workflows—is significant. The reusable workflow pattern demonstrates a more efficient and resource-friendly queuing mechanism, avoiding the premature runner launches seen in direct matrix configurations. This suggests that the underlying logic for job creation and event dispatch differs, offering a potential blueprint for improvement.
Community Questions and Future Directions
The discussion author posed three critical questions to the GitHub team, reflecting the community's need for clarity and potential enhancements:
- Is the immediate
queuedevent formax-parallel-held-back matrix jobs the intended behavior? - Could there be a distinct status or event, similar to
waitingfor environment protection rules, that signifies a job is "created but not yet eligible to run" due tomax-parallel? This would empower autoscalers to make more informed decisions. - Why does the reusable-workflow matrix behave differently from the direct matrix?
While the initial response from GitHub was a standard "feedback submitted" message, the insights shared by andrewdibiasio6 and the community are invaluable. Addressing this behavior could significantly enhance the efficiency of development activities on GitHub Actions, leading to better resource utilization and more accurate software project metrics for CI/CD pipelines. The community's ongoing engagement is vital in shaping the future of the platform.
