concurrency

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrencyManager

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

ConcurrencyManager manages concurrent operations and limits

func NewConcurrencyManager

func NewConcurrencyManager(config *ManagerConfig) (*ConcurrencyManager, error)

NewConcurrencyManager creates a new concurrency manager

func (*ConcurrencyManager) GetActiveWorkers

func (m *ConcurrencyManager) GetActiveWorkers() int

GetActiveWorkers returns the number of active workers

func (*ConcurrencyManager) GetCompletedTasks

func (m *ConcurrencyManager) GetCompletedTasks() int64

GetCompletedTasks returns the number of completed tasks

func (*ConcurrencyManager) GetConfig

func (m *ConcurrencyManager) GetConfig() *ManagerConfig

GetConfig returns the configuration for the concurrency manager

func (*ConcurrencyManager) GetFailedTasks

func (m *ConcurrencyManager) GetFailedTasks() int64

GetFailedTasks returns the number of failed tasks

func (*ConcurrencyManager) GetPendingTasks

func (m *ConcurrencyManager) GetPendingTasks() int

GetPendingTasks returns the number of pending tasks

func (*ConcurrencyManager) GetQueueCapacity

func (m *ConcurrencyManager) GetQueueCapacity() int

GetQueueCapacity returns the capacity of the task queue

func (*ConcurrencyManager) GetQueueSize

func (m *ConcurrencyManager) GetQueueSize() int

GetQueueSize returns the size of the task queue

func (*ConcurrencyManager) GetStats

func (m *ConcurrencyManager) GetStats() *ConcurrencyStats

GetStats returns statistics for the concurrency manager

func (*ConcurrencyManager) GetUtilization

func (m *ConcurrencyManager) GetUtilization() float64

GetUtilization returns the worker utilization

func (*ConcurrencyManager) IsRunning

func (m *ConcurrencyManager) IsRunning() bool

IsRunning returns if the concurrency manager is running

func (*ConcurrencyManager) SetConfig

func (m *ConcurrencyManager) SetConfig(config *ManagerConfig) error

SetConfig sets the configuration for the concurrency manager

func (*ConcurrencyManager) Start

func (m *ConcurrencyManager) Start() error

Start starts the concurrency manager

func (*ConcurrencyManager) Stop

func (m *ConcurrencyManager) Stop()

Stop stops the concurrency manager

func (*ConcurrencyManager) Submit

func (m *ConcurrencyManager) Submit(task Task) error

Submit submits a task for execution

func (*ConcurrencyManager) SubmitWithTimeout

func (m *ConcurrencyManager) SubmitWithTimeout(task Task, timeout time.Duration) error

SubmitWithTimeout submits a task for execution with a timeout

type ConcurrencyStats

type ConcurrencyStats struct {
	// ActiveWorkers is the number of active workers
	ActiveWorkers int32
	// PendingTasks is the number of pending tasks
	PendingTasks int32
	// CompletedTasks is the number of completed tasks
	CompletedTasks int64
	// FailedTasks is the number of failed tasks
	FailedTasks int64
	// TotalTasks is the total number of tasks
	TotalTasks int64
	// AverageTaskDuration is the average task duration
	AverageTaskDuration time.Duration
	// MaxTaskDuration is the maximum task duration
	MaxTaskDuration time.Duration
	// MinTaskDuration is the minimum task duration
	MinTaskDuration time.Duration
	// TotalTaskDuration is the total task duration
	TotalTaskDuration time.Duration
	// QueuedTasks is the number of queued tasks
	QueuedTasks int32
	// WorkerScalingEvents is the number of worker scaling events
	WorkerScalingEvents int64
	// LastScaleUpTime is the time of the last scale up
	LastScaleUpTime time.Time
	// LastScaleDownTime is the time of the last scale down
	LastScaleDownTime time.Time
}

ConcurrencyStats tracks statistics for the concurrency manager

type ManagerConfig

type ManagerConfig struct {
	// MaxWorkers is the maximum number of workers
	MaxWorkers int
	// MinWorkers is the minimum number of workers
	MinWorkers int
	// InitialWorkers is the initial number of workers
	InitialWorkers int
	// QueueSize is the size of the task queue
	QueueSize int
	// WorkerIdleTimeout is the timeout for idle workers
	WorkerIdleTimeout time.Duration
	// TaskTimeout is the timeout for tasks
	TaskTimeout time.Duration
	// EnableAutoScaling enables automatic worker scaling
	EnableAutoScaling bool
	// ScaleUpThreshold is the threshold for scaling up workers
	ScaleUpThreshold float64
	// ScaleDownThreshold is the threshold for scaling down workers
	ScaleDownThreshold float64
	// ScaleCheckInterval is the interval for checking if workers need to be scaled
	ScaleCheckInterval time.Duration
	// ScaleUpStep is the number of workers to add when scaling up
	ScaleUpStep int
	// ScaleDownStep is the number of workers to remove when scaling down
	ScaleDownStep int
}

ManagerConfig represents configuration for the concurrency manager

func DefaultManagerConfig

func DefaultManagerConfig() *ManagerConfig

DefaultManagerConfig returns default configuration for the concurrency manager

type Task

type Task interface {
	// Execute executes the task
	Execute(ctx context.Context) error
	// ID returns the task ID
	ID() string
	// Priority returns the task priority
	Priority() int
}

Task represents a task to be executed

Jump to

Keyboard shortcuts

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