capacity

package
v0.22.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package capacity coordinates process-wide instance capacity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

Allocator is one scale set's view of a process-wide Broker.

func (*Allocator) Acquire

func (a *Allocator) Acquire(ctx context.Context) (*Lease, error)

Acquire waits until this scale set may use one instance slot or ctx is cancelled. Requests below a scale set's minimum take priority over surplus.

type Broker

type Broker struct {
	// contains filtered or unexported fields
}

Broker arbitrates runner capacity across all registered scale sets. Capacity needed to satisfy another scale set's minimum is reserved before surplus is handed out, and surplus waiters are served in FIFO order.

A non-positive limit is unlimited.

func NewBroker

func NewBroker(limit int) *Broker

NewBroker creates a process-wide capacity broker.

func (*Broker) InUse

func (b *Broker) InUse() int

InUse returns the number of currently leased instance slots.

func (*Broker) Limit

func (b *Broker) Limit() int

Limit returns the configured process-wide limit. A non-positive value means unlimited.

func (*Broker) Register

func (b *Broker) Register(name string, minimum int) *Allocator

Register creates an allocator for a scale set. Callers must register every scale set before any of them starts acquiring capacity so all minimums are reserved from the beginning.

type Lease

type Lease struct {
	// contains filtered or unexported fields
}

Lease owns one Broker slot. Release is idempotent so lifecycle cleanup can safely converge from job-complete, crash, drain, and shutdown paths.

func (*Lease) Release

func (l *Lease) Release()

Release returns the slot to the broker.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL