Skip to content

Add experimental worker.GetSlotUsage - #2858

Open
johanngan wants to merge 1 commit into
mainfrom
johanngan/worker-slot-usage
Open

johanngan wants to merge 1 commit into
mainfrom
johanngan/worker-slot-usage

Conversation

@johanngan

@johanngan johanngan commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

Expose a snapshot of a worker's task slot usage per task kind: the number of slots currently marked used, and when a slot was last marked used or a used slot released. The APIs are experimental.

Workers implement a separate, optional worker.SlotUsageProvider interface, wrapped by the package-level GetSlotUsage function, so that the worker.Worker interface is unchanged.

Why?

This API exposes some task-processing metrics that the default worker mostly already tracks internally through its trackingSlotSupplier. This gives SDK users more visibility into what a worker is doing, such as exactly how long a worker been idle. The intended first user is idle shutdown in the Lambda worker package.

Checklist

  1. How was this tested:
    Unit tests added.

  2. Any docs updates needed?
    In-repo docs updated.

Expose a snapshot of a worker's task slot usage per task kind: the
number of slots currently marked used, and when a slot was last marked
used or a used slot released. Together these let callers tell exactly
how long a worker has had no tasks in progress, including tasks that
started and finished between two snapshots. The intended first user is
idle shutdown in the Lambda worker.

Workers implement a separate, optional worker.SlotUsageProvider
interface, wrapped by the package-level GetSlotUsage function, so that
the worker.Worker interface is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@johanngan
johanngan marked this pull request as ready for review November 6, 2026 21:56
@johanngan
johanngan requested a review from a team as a code owner November 6, 2026 21:56
@johanngan
johanngan added this pull request to stack #2859 November 6, 2026 21:59
Comment thread internal/slot_usage.go
// NOTE: Experimental
//
// Exposed as: [go.temporal.io/sdk/worker.SlotUsage]
type SlotUsage struct {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This API's a bit more general than just a simple combined slot counter, but pretty free given the internal tracking code, and I think maybe more generally useful as a public API.

@Sushisource Sushisource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM but would like @Quinn-With-Two-Ns to sign off too

Comment thread internal/slot_usage.go
// UsedSlotsLastChanged is when a task last started or finished, or the zero time if no task has
// started since the worker was created. A task that starts and finishes between two snapshots
// still changes it.
UsedSlotsLastChanged time.Time

@johanngan johanngan Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Potentially worth discussing if we'd prefer this to be exposed as a time delta (i.e. time.Duration) since the last change, rather than an absolute time. In Go time.Time stores both wall and monotonic time and uses the latter for most difference calculations, but that's not true in other languages so we'd have to worry about exposing wall time vs. monotonic time, and about interactions between the Rust core's time representations and the relevant core-based languages' clocks.

As a public API, absolute time seems more useful than a time delta, so it's what I tentatively went with here.

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.

3 participants