Repository navigation
Conversation
Add a per-queue deadline_scaling block (throughput_rps, cold_start_seconds, max_replicas, optional safety_factor) and the gauge llm_d_async_async_deadline_required_replicas. Each backlog poll computes it next to the deadline-proximity snapshot, from the same cumulative counts: the maximum over bucket boundaries t with queued items of B(t) / (R * (t - C) * safety_factor), rounded up and capped at max_replicas; items due at or before the cold start pin it to max_replicas. Both the redis-sortedset and sql transports report those counts, so both get the gauge; flows expose a queue's settings through a DeadlineScaling method, and the pipeline module does not change. Fixes llm-d#465 Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
Compare the demand with max_replicas while it is still a float: a tiny throughput_rps or safety_factor can push it past the int range or to +Inf, and the conversion then gave -9223372036854775808 on linux/amd64. Also return at least 1 for any positive demand, so the 1e-9 rounding tolerance can no longer turn queued work into 0 replicas. Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
Review on llm-d#526: late work shouldn't drive scaling, and a failed backlog read should drop the required-replicas series so KEDA's fallback applies instead of reading 0. QueueBacklogStat gets ExpiringCountsFailed, since zeroed counts look like an empty queue. The docs say the per-queue value is right only when each queue has its own deployment, and to aggregate processor replicas with max(). Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
Queues that share a deployment need their deadline work summed before the division: summing their per-queue gauges over-counts and max() under-counts (llm-d#526 review). Worker pools get an optional deadline_scaling block, and the backlog poller publishes llm_d_async_async_pool_deadline_required_replicas, labelled by pool_name. Within each horizon, a queue's unexpired items are divided by its throughput_rps (the queue's own, else the pool's) and summed across the pool before the division by (t - C) * s. RequiredReplicas now takes this work per bucket and AddWork builds it, so a single queue is a pool of one. A failed deadline read on any of a pool's queues drops the pool's series. Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c407518ee1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| | `llm_d_async_async_inference_latency_time_millis` | Histogram | Time in milliseconds spent calling `llm-d-router` (or other inference gateway), measured around each request attempt. Isolates "model time" from "queue time". Always registered. | | ||
| | `llm_d_async_async_queue_residence_time_millis` | Histogram | Time in milliseconds a message spent buffered in-process, from broker ingestion until a worker pulled it for processing. Measures the async delay introduced by the system (queue time). Always registered. | | ||
| | `llm_d_async_async_deadline_proximity_millis` | Histogram | Snapshot histogram of time in milliseconds remaining until each queued item's deadline, rebuilt once per backlog poll from exact cumulative `ZCOUNT` counts per bucket (`le="0"` holds items past their deadline but still queued; higher buckets are cumulative, so every item counts in each bucket it expires in). Redis sorted-set only; Cloud Pub/Sub cannot expose per-item deadlines. Because each poll replaces the snapshot, the series is not monotonic — `rate()` is meaningless; use `histogram_quantile` per scrape. The `_sum` is estimated from bucket midpoints. | | ||
| | `llm_d_async_async_deadline_required_replicas` | Gauge | Replicas a queue needs to finish its queued items before their deadlines, recomputed each backlog poll from the deadline-proximity counts and the queue's `deadline_scaling` settings (`throughput_rps` R, `cold_start_seconds` C, `max_replicas`, optional `safety_factor` s): the maximum over bucket boundaries t > 0 of B(t) / (R · (t − C) · s), where B(t) counts the items due within t that haven't expired, rounded up and capped at `max_replicas`. Expired items don't count; items due within C pin it to `max_replicas`. A failed deadline read drops the series for that poll, so KEDA's `fallback` applies. Only queues with `deadline_scaling`, on `redis-sortedset` and `sql`. The value is per queue, so it is right only when each queue has its own deployment; for queues that share one, use the pool gauge below. Every processor replica publishes the same value, so aggregate across them with `max()`. Meant as a KEDA trigger with threshold 1. | |
There was a problem hiding this comment.
Require KEDA to reject empty results before relying on fallback
With the documented max(...) aggregation, deleting the last matching series produces an empty query result. KEDA's Prometheus scaler defaults ignoreNullValues to true, so it interprets that result as zero rather than a scaler error; configuring fallback alone does not change this. A deadline-read outage can therefore request a scale-down instead of activating the fallback promised here. Document that the trigger must set ignoreNullValues: "false" alongside its fallback configuration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, with the default ignoreNullValues: true KEDA reads the empty result as 0. Fixed in 11da710: the docs now say the trigger needs ignoreNullValues: "false" for the fallback to apply.
| if horizon <= coldStart { | ||
| return c.MaxReplicas | ||
| } | ||
| need = math.Max(need, work[i]/((horizon-coldStart).Seconds()*safety)) |
There was a problem hiding this comment.
Handle cold starts between histogram boundaries
When cold_start_seconds falls between bucket boundaries, this guard misses items due before cold start. For example, with throughput 2, cold start 90 seconds, and a cap of 10, an item due in 75 seconds contributes zero through the 60-second bucket and one starting at 120 seconds. The calculator returns 1 rather than the documented cap of 10 because no nonempty horizon satisfies this condition. Include a count boundary at cold start or conservatively handle the bucket that straddles it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 11da710: new work in the bucket that starts before C now pins the result to max_replicas, so your example returns 10. Test: due in the bucket around the cold start.
| if work, ok := poolWork[name]; ok && !poolPartial[name] { | ||
| metrics.SetPoolDeadlineRequiredReplicas(name, cfg.RequiredReplicas(buckets, work)) | ||
| } else { | ||
| metrics.RemovePoolDeadlineRequiredReplicas(name) |
There was a problem hiding this comment.
Publish zero demand for configured pools with no queues
After a Redis hot reload removes the final queue from a configured pool, QueueBacklog succeeds but poolWork[name] has no entry, so this branch deletes the pool gauge. Empty queue configurations are explicitly supported by LoadSortedSetConfigAllowEmptyQueues; this is zero demand, not an unavailable source. Consumers configured to invoke fallback on missing metrics will retain fallback replicas instead of scaling the drained pool down. Publish zero for a successful empty-pool snapshot and reserve deletion for failed or unsupported reads.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 11da710: after a successful read, a pool with no queues reads 0; a failed read still drops the series. Test: TestPollBacklogPublishesZeroForPoolWithoutQueues.
A cold start between two deadline-proximity boundaries let items that may be due before it count as ordinary work: new work in the bucket that starts before the cold start now pins the result to max_replicas, as work due within it does. A pool with no queues after a successful read, e.g. after a reload removed the last one, now reads 0 instead of losing its series, so an autoscaler scales it down instead of holding its fallback replicas. The docs now note that KEDA uses its fallback for a missing series only when the trigger sets ignoreNullValues to "false"; by default it reads the empty result as 0. Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
|
Note to other maintainers do not merge before #526 |
What does this PR do?
Stacked on #526: until it merges, this branch carries its 4 commits, and the change here is the last three. Adds the per-pool gauge agreed in #526's review:
llm_d_async_async_pool_deadline_required_replicas, labelled bypool_name.deadline_scalingblock next togate_type/gate_params, with the queue block's four fields. A queue's ownthroughput_rpsoverrides the pool's.RequiredReplicasnow takes that work andAddWorkbuilds it; the per-queue gauge is the one-queue case.Not done:
pool_nameis the async worker pool, so two worker pools that send to one deployment still undercount; that needs an explicitscaling_group.Why is this change needed?
Queues that share a deployment need their work summed before the division:
sum()of the per-queue gauges over-counts andmax()under-counts. The two examples from the review are test cases (2, not 3; 4, not 2).How was this tested?
Table tests for the pool sums and the throughput override; poll-loop tests for the pool series (set, absent without settings, 0 without queues, dropped on a failed read); a table case for work in the bucket around the cold start;
loadWorkerPoolsrejects an invalid pool block.go vetandgo test -raceon the changed packages,make testandmake lintpass (Go 1.26.0, Darwin arm64). Not run: a KEDA ScaledObject against the pool gauge.Checklist
git commit -s) per DCOmake test)make lint)Related Issues
Fixes #465
Release note