Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPoolShutdown is returned when attempting to Submit a job to a shutdown pool ErrPoolShutdown = errors.New("pool is shutdown") // ErrQueueFull is returned when the job queue is at capacity and cannot accept new jobs ErrQueueFull = errors.New("queue is full") // ErrTimeout is returned when a job submission times out ErrTimeout = errors.New("submission timeout") // ErrInvalidConfig is returned when pool configuration is invalid ErrInvalidConfig = errors.New("invalid pool configuration") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds the configuration for the pool
type Metrics ¶
type Metrics interface {
// QueueDepth returns the current number of jobs in the queue
QueueDepth() int
// ActiveWorkers returns the current number of active workers
ActiveWorkers() int
// JobsProcessed returns the total number of jobs processed
JobsProcessed() int64
// JobsRejected returns the total number of jobs rejected
JobsRejected() int64
// AvgJobLatency returns the average job latency
AvgJobLatency() time.Duration
}
Metrics provides observability into pool behavior
type Option ¶
type Option func(*Config)
Option is a functional option for configuring the pool
func WithMaxWorkers ¶
WithMaxWorkers sets the maximum number of workers Default: runtime.NumCPU()
func WithMetricsEnabled ¶
WithMetricsEnabled enables or disables metrics collection Default: true
func WithMinWorkers ¶
WithMinWorkers sets the minimum number of workers Default: 1
func WithQueueSize ¶
WithQueueSize sets the bounded queue capacity Default: 1000
func WithScaleCooldown ¶
WithScaleCooldown sets the minimum duration between scaling operations Default: 5s
func WithScaleDownIdleDuration ¶
WithScaleDownIdleDuration sets the idle duration before scaling down workers Default: 30s
func WithScaleUpThreshold ¶
WithScaleUpThreshold sets the queue utilization percentage (0.0 to 1.0) that triggers scale-up Default: 0.7 (70%)
type Pool ¶
type Pool interface {
// Submit Submits a job to the pool for execution
// Returns ErrPoolShutdown if the pool is shutdown
// Blocks until the job is enqueued or context is cancelled
Submit(ctx context.Context, job Job) error
// Shutdown gracefully shuts down the pool
// Waits for in-flight jobs to complete within the context timeout
Shutdown(ctx context.Context) error
// Metrics returns the pool metrics
Metrics() Metrics
}
Pool represents a worker pool that can execute jobs concurrently
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
batch_processor
command
Package main provides a batch processing example using the adaptive pool.
|
Package main provides a batch processing example using the adaptive pool. |
|
comparison
command
Package main provides a simple benchmark comparison tool for the adaptive pool.
|
Package main provides a simple benchmark comparison tool for the adaptive pool. |
|
http_server
command
Package main provides an HTTP server example using the adaptive pool.
|
Package main provides an HTTP server example using the adaptive pool. |
|
one_million_simulator/naive
command
Package main provides a naive simulator that spawns a goroutine for every task.
|
Package main provides a naive simulator that spawns a goroutine for every task. |
|
one_million_simulator/with_pool
command
Package main provides a 1 Million RPS simulator to demonstrate the adaptive pool's behavior.
|
Package main provides a 1 Million RPS simulator to demonstrate the adaptive pool's behavior. |