Documentation
¶
Index ¶
- type PoolManagerConfig
- type PoolManagerStats
- type PoolStats
- type ResourcePool
- func (p *ResourcePool) Acquire(ctx context.Context) (interface{}, error)
- func (p *ResourcePool) Close()
- func (p *ResourcePool) GetAvailable() int
- func (p *ResourcePool) GetInUse() int
- func (p *ResourcePool) GetName() string
- func (p *ResourcePool) GetSize() int
- func (p *ResourcePool) GetStats() *PoolStats
- func (p *ResourcePool) Release(resource interface{})
- func (p *ResourcePool) SetMaxIdleTime(maxIdleTime time.Duration)
- func (p *ResourcePool) SetMaxLifetime(maxLifetime time.Duration)
- func (p *ResourcePool) SetValidateFunc(validate func(interface{}) bool)
- type ResourcePoolManager
- func (m *ResourcePoolManager) CreatePool(name string, size int, factory func() (interface{}, error), ...) (*ResourcePool, error)
- func (m *ResourcePoolManager) GetPool(name string) (*ResourcePool, error)
- func (m *ResourcePoolManager) GetStats() *PoolManagerStats
- func (m *ResourcePoolManager) ListPools() []string
- func (m *ResourcePoolManager) RemovePool(name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PoolManagerConfig ¶
type PoolManagerConfig struct {
// DefaultPoolSize is the default size of pools
DefaultPoolSize int
// DefaultMaxIdleTime is the default maximum idle time for resources
DefaultMaxIdleTime time.Duration
// DefaultMaxLifetime is the default maximum lifetime for resources
DefaultMaxLifetime time.Duration
// EnableResourceValidation enables resource validation
EnableResourceValidation bool
// EnableResourceCleanup enables resource cleanup
EnableResourceCleanup bool
// EnablePoolScaling enables automatic pool scaling
EnablePoolScaling bool
// MinPoolSize is the minimum size of pools when scaling
MinPoolSize int
// MaxPoolSize is the maximum size of pools when scaling
MaxPoolSize int
// ScaleUpThreshold is the threshold for scaling up pools
ScaleUpThreshold float64
// ScaleDownThreshold is the threshold for scaling down pools
ScaleDownThreshold float64
// ScaleCheckInterval is the interval for checking if pools need to be scaled
ScaleCheckInterval time.Duration
}
PoolManagerConfig represents configuration for the resource pool manager
func DefaultPoolManagerConfig ¶
func DefaultPoolManagerConfig() *PoolManagerConfig
DefaultPoolManagerConfig returns default configuration for the resource pool manager
type PoolManagerStats ¶
type PoolManagerStats struct {
// TotalPools is the total number of pools
TotalPools int
// TotalResources is the total number of resources across all pools
TotalResources int
// TotalAvailable is the total number of available resources across all pools
TotalAvailable int
// TotalInUse is the total number of resources in use across all pools
TotalInUse int
// PoolStats is a map of pool name to pool statistics
PoolStats map[string]*PoolStats
}
PoolManagerStats tracks statistics for the resource pool manager
type PoolStats ¶
type PoolStats struct {
// Size is the size of the pool
Size int
// Available is the number of available resources
Available int
// InUse is the number of resources in use
InUse int
// Created is the number of resources created
Created int64
// Acquired is the number of resources acquired
Acquired int64
// Released is the number of resources released
Released int64
// Errors is the number of errors
Errors int64
// Timeouts is the number of timeouts
Timeouts int64
// MaxWaitTime is the maximum wait time for a resource
MaxWaitTime time.Duration
// TotalWaitTime is the total wait time for resources
TotalWaitTime time.Duration
// AvgWaitTime is the average wait time for a resource
AvgWaitTime time.Duration
}
PoolStats tracks statistics for a resource pool
type ResourcePool ¶
type ResourcePool struct {
// contains filtered or unexported fields
}
ResourcePool represents a pool of resources
func (*ResourcePool) Acquire ¶
func (p *ResourcePool) Acquire(ctx context.Context) (interface{}, error)
Acquire acquires a resource from a pool
func (*ResourcePool) GetAvailable ¶
func (p *ResourcePool) GetAvailable() int
GetAvailable returns the number of available resources
func (*ResourcePool) GetInUse ¶
func (p *ResourcePool) GetInUse() int
GetInUse returns the number of resources in use
func (*ResourcePool) GetName ¶
func (p *ResourcePool) GetName() string
GetName returns the name of the pool
func (*ResourcePool) GetSize ¶
func (p *ResourcePool) GetSize() int
GetSize returns the size of the pool
func (*ResourcePool) GetStats ¶
func (p *ResourcePool) GetStats() *PoolStats
GetStats returns statistics for the resource pool
func (*ResourcePool) Release ¶
func (p *ResourcePool) Release(resource interface{})
Release releases a resource back to the pool
func (*ResourcePool) SetMaxIdleTime ¶
func (p *ResourcePool) SetMaxIdleTime(maxIdleTime time.Duration)
SetMaxIdleTime sets the maximum idle time for resources
func (*ResourcePool) SetMaxLifetime ¶
func (p *ResourcePool) SetMaxLifetime(maxLifetime time.Duration)
SetMaxLifetime sets the maximum lifetime for resources
func (*ResourcePool) SetValidateFunc ¶
func (p *ResourcePool) SetValidateFunc(validate func(interface{}) bool)
SetValidateFunc sets the validation function for the pool
type ResourcePoolManager ¶
type ResourcePoolManager struct {
// contains filtered or unexported fields
}
ResourcePoolManager manages resource pools for efficient resource utilization
func NewResourcePoolManager ¶
func NewResourcePoolManager(config *PoolManagerConfig) *ResourcePoolManager
NewResourcePoolManager creates a new resource pool manager
func (*ResourcePoolManager) CreatePool ¶
func (m *ResourcePoolManager) CreatePool(name string, size int, factory func() (interface{}, error), cleanup func(interface{})) (*ResourcePool, error)
CreatePool creates a new resource pool
func (*ResourcePoolManager) GetPool ¶
func (m *ResourcePoolManager) GetPool(name string) (*ResourcePool, error)
GetPool gets a resource pool by name
func (*ResourcePoolManager) GetStats ¶
func (m *ResourcePoolManager) GetStats() *PoolManagerStats
GetStats returns statistics for the resource pool manager
func (*ResourcePoolManager) ListPools ¶
func (m *ResourcePoolManager) ListPools() []string
ListPools lists all resource pools
func (*ResourcePoolManager) RemovePool ¶
func (m *ResourcePoolManager) RemovePool(name string) error
RemovePool removes a resource pool