Repository navigation
Take job event patches off the scale decision path in the listener - #4668
Open
nikola-jokic wants to merge 5 commits into
Open
nikola-jokic wants to merge 5 commits into
nikola-jokic wants to merge 5 commits into
Conversation
The scaleset listener no longer dissects the message it polls. It owns session management, polling and acking, and hands the whole message to a single Scale call, so acquiring jobs and recording metrics move to the only component that still reads them. That handover is what makes the work parallelisable. The listener used to replay a message one API call at a time, in a fixed order: every job started patch, then every job completed, then the scale patch. The job events touch distinct EphemeralRunners and carry no ordering between them, so they now run across a bounded worker pool, with the worker that patches the EphemeralRunnerSet running alongside them. The one ordering that does matter is kept. deleteIdleEphemeralRunners skips a runner only once it carries a job request ID, so a patch that lowers the replica count could offer up a runner that just picked up a job if it were published while job started patches were still in flight. The scaling worker therefore waits for the event workers on a scale down, and only then. A patch that scales up or holds cannot delete anything. Kubernetes has no bulk write: get, create, update, patch and delete are single-resource verbs, and deletecollection is the only collection-scoped mutating verb there is, so N events cannot be collapsed into fewer requests. Server side apply is a PATCH on one object URI and does not change that. Issuing the N patches concurrently over the one HTTP/2 connection is the available win; the alternative is writing fewer objects, which trades N cheap independent writes for one contended, watch-amplifying, size-bounded write. The pool size is configurable through listenerConfig.scaler.workers, alongside the existing qps and burst, and defaults to 10: two calls per event keeps a full pool well inside the default QPS budget. Statistics are now cached by the scaler. The listener stopped tracking them, and a long poll that times out carries no message at all, so without the cache an idle scale set would stop converging. Co-authored-by: Copilot App <[email protected]>
Scale used to hold the replica patch back whenever the target dropped, so that every job started patch had landed before the runner set controller could act on a lower count. The reasoning was that deleteIdleEphemeralRunners skips a runner only once it carries a job ID, so a runner that had just picked up a job could otherwise be deleted. That guard was unreachable. The controller only deletes idle runners under Spec.PatchID == 0, and setDesiredWorkerState emits patch ID 0 only when the target is unchanged and equal to MinRunners, or on the very first patch, when no previous target exists. Neither can coincide with a falling target, so a scale down never reaches the deletion path. Exhaustively walking message sequences over every MinRunners/MaxRunners pair finds no state where the two occur together. So the replica patch has no reason to wait, and good reason to go first: it is the only patch that creates runners, and therefore the one new jobs wait on, while the job event patches are bookkeeping the controller reads later. Sending it first also keeps it clear of the client rate limiter, which a large batch of event patches would otherwise drain ahead of it. The job events still have to land before Scale returns. The listener acks the message the moment it does, and nothing other than these patches ever writes Status.JobID, so a patch dropped after the ack would leave a busy runner looking idle to the scale down that a later patch ID 0 permits. Co-authored-by: Copilot App <[email protected]>
The scaler issued every API call a message asked for before returning, and the listener acks only once it returns. A full batch of job started events is 50 of them, two calls each, so the next scale decision sat behind 100 calls of bookkeeping. Those patches are not what new jobs wait on. Only the desired runner count creates runners; Status.JobID is a hint the runner set consults when choosing which idle runner to delete, and the Actions service rejects the deletion of a runner whose job is still running either way. Publish the desired count first, hand the job started events to a background pool, and acquire after. Acquiring last costs the round trip of the scale patch and saves the whole batch, and the scale decision is unaffected: it comes from msg.Statistics, a snapshot the service took when it built the message, so jobs acquired now are reported as assigned in a later one. Give the two kinds of traffic their own clients. Sharing one token bucket is what let the job patches delay the scale patch, so splitting them is what makes the reordering worth anything; backgrounding alone would just move the same queue. Measured against a 5ms API server and a 50ms Actions service, at a full 50 event batch: scale patch reaches the API server 1.971s -> 6ms listener loop 2.02s -> 107ms/msg The loop no longer spends the rate limit inline, so its cost is now the two service round trips rather than the batch size. This does not raise throughput. Job patches still cost two calls per event, so the job client sustains qps/2 job starts per second, and the queue is bounded by the real job start rate rather than by how fast the listener polls: a faster loop polls more often and carries proportionally fewer events. Measured at qps 40, the queue stays empty through 18 starts/sec and degrades gradually past 20 rather than falling over. Close drains the queue, since the message these patches came from was acked long before they run. Co-authored-by: Copilot App <[email protected]>
nikola-jokic
force-pushed
the
nikola-jokic-parallel-listener-scaler
branch
from
September 18, 2026 13:06
60ffe93 to
2877779
Compare
nikola-jokic
added a commit
that referenced
this pull request
Sep 28, 2026
Limit the PR to chart fixes supported by master, without the listener API and SDK changes from #4668. Co-authored-by: Copilot App <[email protected]>
4 tasks done
nikola-jokic
marked this pull request as ready for review
November 27, 2026 17:27
nikola-jokic
requested review from
a team,
Steve-Glass,
mumoshu,
rentziass and
toast-gear
as code owners
November 27, 2026 17:27
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The priority test does not verify production rate-limit separation, leaving shared-limiter regressions undetected without a test that exhausts the job budget and confirms scale patches can proceed.
1 open issue
What changed in this PR
Moves job-start metadata patches into background workers so the listener can publish desired runner counts without waiting for those patches.
Changes:
- Adds ten workers, a bounded queue, retry backoff, and shutdown draining.
- Separates scale-patch and job-status rate limits, with scaling and acquisition preceding job-event enqueueing.
- Adds asynchronous processing tests and documents backpressure, rate limits, and potential metadata loss.
| File | Description |
|---|---|
| docs/gha-runner-scale-set-controller/README.md | Documents acknowledgment ordering, queue backpressure, and shutdown risks. |
| cmd/ghalistener/scaler/scaler.go | Implements background job patches, separate rate limits, and queue draining. |
| cmd/ghalistener/scaler/scaler_test.go | Updates test helpers to use the job-status client. |
| cmd/ghalistener/scaler/scaler_apiserver_test.go | Updates API-server tests for the job-status client. |
| cmd/ghalistener/scaler/scale_async_test.go | Adds priority, backpressure, retry, and cancellation tests. |
| cmd/ghalistener/scaler/message_test.go | Updates ordering assertions and synchronizes asynchronous patch recording. |
| cmd/ghalistener/main.go | Adds a 30-second shutdown drain window. |
| charts/gha-runner-scale-set/values.yaml | Clarifies separate job-status and scaling rate limits in comments. |
| charts/gha-runner-scale-set-experimental/values.yaml | Updates comments describing QPS and burst scope. |
Review effort: Balanced
Comment on lines
+111
to
+115
| // Keep job patch traffic from consuming the scale patch's rate limit. | ||
| scaleConf := rest.CopyConfig(conf) | ||
| scaleConf.QPS = defaultScaleQPS | ||
| scaleConf.Burst = defaultScaleBurst | ||
| scaleClientset, err := kubernetes.NewForConfig(scaleConf) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
1b2c924fe42630be88d9ead7da04684750f70ad4↓ One E2E attempt timed out before passing on rerun; crashes can lose queued metadata, and current-base performance has not been benchmarked.
Moves job-start metadata patches off the listener's scale-decision path using the existing
actions/scalesetAPI.The problem
The listener acknowledges a message only after
Scalereturns. Synchronous job-start status patches therefore delay publishing the desired runner count and processing subsequent messages. Currentmasteralready reduced each job-start update to one Kubernetes API request; the earlier two-request measurements no longer describe the baseline.The change
qpsandburstsettings now govern job-status traffic; total listener traffic can exceed those settings by the separate scale budget.Measured
The previous performance numbers used the old two-request implementation and have not been remeasured against the current base. The regression tests verify that a blocked, rate-limited job-status request does not block the next scale patch.
What this does not do
This does not increase the configured job-status API throughput. When the queue fills, later messages wait for space, so sustained overload can delay subsequent scale decisions.
FinishedRunnerCleanupPatchIDis unchanged.Risk
Job-start updates are held in memory after acknowledgment. A crash or shutdown drain timeout can lose pending metadata and leave
Status.JobIDstale. Scale-down can then attempt to remove a busy runner; the existing runner-set removal and live-pod finalization paths consult the Actions service and preserve a runner when it reportsJobStillRunningError. Job acquisition remains synchronous and precedes acknowledgment.Validation
go test -race -timeout 120s -count=1 ./cmd/ghalistener/..., with Kubernetes 1.37.0 envtest assets enabled.go test -timeout 120s -count=1.golangci-lintv2.15.0 passed locally.auth-proxy-setupattempt timed out waiting for one of three workflow jobs; a targeted rerun passed.Note for reviewers
The earlier configuration fields, unbounded queue, generated CRD/schema changes, and obsolete two-request performance claims were removed. The crash window and bounded-queue backpressure above are intentional tradeoffs requiring review.