Skip to content

Adding algorithm for GCP CloudRun WorkerPools and similar compute providers#59

Open
02strich wants to merge 3 commits into
mainfrom
stefan/cr-algo
Open

Adding algorithm for GCP CloudRun WorkerPools and similar compute providers#59
02strich wants to merge 3 commits into
mainfrom
stefan/cr-algo

Conversation

@02strich

@02strich 02strich commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

What was changed

Introduce a rate-based scaling algorithm that sizes the worker pool from EWMA-smoothed arrival, dispatch, and per-consumer capacity estimates. Desired worker count is the maximum of a utilization-target model and a Halfin-Whitt
square-root staffing model, bounded by min/max count, capped per scale-up step, and gated by asymmetric scale-up/scale-down cooldowns plus a no-sync-match quiet period. Includes unit tests covering the sizing and scaling decisions

This is an implementation of the algorithm in #54

Why?

The existing scaling algorithm makes a set of assumption that are true for Lambda, but not for other compute providers like GCP CloudRun or AWS ECS. This adds a new scaling algorithm more suited to these other compute providers.

02strich added 3 commits June 16, 2026 22:47
Skip waiting on the long-running operation returned by UpdateWorkerPool so the activity returns more quickly. Whether the workers connect correctly wouldn’t be verified by it completing anyway.
Swap the silent noopLogger for a fallbackLogger that writes to stderr via the standard library so logs from outside an activity context (panic) or from interceptors returning nil are still visible. Add tests covering keyvals formatting, level routing, normalizeSDKLogger branches, and the non-activity-context fallback path.
Introduce a rate-based scaling algorithm that sizes the worker pool from
EWMA-smoothed arrival, dispatch, and per-consumer capacity estimates. Desired
worker count is the maximum of a utilization-target model and a Halfin-Whitt
square-root staffing model, bounded by min/max count, capped per scale-up step,
and gated by asymmetric scale-up/scale-down cooldowns plus a no-sync-match quiet
period. Includes unit tests covering the sizing and scaling decisions.

Also reject Inf and NaN values in validateFloat64InMap so float config keys must be real numbers.
@02strich 02strich marked this pull request as ready for review June 17, 2026 19:33
@02strich 02strich requested a review from a team as a code owner June 17, 2026 19:33

@gcristea-temporal gcristea-temporal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, only found one nit.

Comment on lines +119 to +121
if math.IsInf(val, 0) || math.IsNaN(val) {
return serviceerror.NewInvalidArgumentf("%s must be a real float", key)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think this check should happen before the check against minValue. Maybe first convert to float64 and checking would make this easier to read.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why do you think it matters? (b/c of the -inf case?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about the case where val is NaN. For that situation the first check (line 116) will return the error.

@gcristea-temporal

Copy link
Copy Markdown
Contributor

$\int or\mu las$

@ericbriffa ericbriffa requested a review from a team June 18, 2026 19:51
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.

2 participants