Repository navigation
Conversation
Contributor
Author
|
Draft status until we're happy that this client-side tuner approach is the right one |
02strich
reviewed
Oct 23, 2026
Sushisource
reviewed
Nov 3, 2026
Sushisource
left a comment
Member
There was a problem hiding this comment.
Overall my take is we could save a lot of code here by exposing the in flight task count you need from the underlying SDK.
I think it's worth it and had AI sketch what needs to be done and it's pretty small:
- In trackingSlotSupplier, add a usedSlotCount() that reads len(usedSlots) under the existing mutex. It could also record the last time a slot was marked used or released, under that same lock, which would let the contrib code compute idle time exactly (my other comment)
- On AggregatedWorker, sum that count across these sub-workers:
- workflowWorker.worker
- workflowWorker.localActivityWorker
- activityWorker.worker
- sessionWorker.creationWorker and sessionWorker.activityWorker
- nexusWorker.worker
To expose it, I think we should just do:
- A function in the worker package, such as worker.InFlightTaskCount(w Worker) (int, bool), marked experimental. It would type-assert to *internal.AggregatedWorker. This adds no interface methods, so it can't break anyone.
The only other downside is we need to then cut a release so this package can depend on the updated version w/ the new function.
Add Options.IdleTimeout, also settable via the TEMPORAL_SERVERLESS_WORKER_IDLE_TIMEOUT environment variable. When set, each invocation shuts down early once the worker has had no tasks of any kind in progress for the timeout, using the same shutdown sequence as the invocation deadline. Idle time is measured from when the last task finished, read from worker.GetSlotUsage, so the timeout is exact. Each invocation adds up to 20% random jitter so that workers that go idle together don't all shut down at once. Idle shutdown is disabled by default. If slot usage can't be read, the invocation logs a warning and runs until the deadline as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
johanngan
force-pushed
the
johanngan/lambda-worker-shutdown-tuner
branch
from
November 6, 2026 21:57
d62b99f to
5d1fdc8
Compare
Contributor
Author
|
Changed the approach of this PR to rely on a base SDK |
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.
What was changed
Add an experimental
Options.IdleTimeout(andTEMPORAL_LAMBDA_IDLE_TIMEOUT, in whole seconds) that gracefully stops the worker before the invocation deadline once it has had no task in hand for at least the given duration. Tasks are counted using the new experimental SlotUsage API added in #2858. The timeout is a lower bound, with a 20% random jitter added so that workers that went idle together don't all shut down at once.Why?
Letting Lambda workers shut themselves down on an idle condition can help save money for spiky or infrequent workloads.
Checklist
Closes COM-478
How was this tested:
In-repo docs updated.