Documentation
¶
Index ¶
- func AllocateParallel(numWorkers uint64, allocator func() (*worker.Process, error)) ([]*worker.Process, error)
- func NewPoolAllocator(ctx context.Context, timeout time.Duration, maxExecs uint64, factory Factory, ...) func() (*worker.Process, error)
- type Command
- type Config
- type DynamicAllocationOpts
- type Factory
- type SupervisorConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Command ¶
Command is a function that returns a new exec.Cmd instance for the given command string.
type Config ¶
type Config struct {
// Debug flag creates new fresh worker before every request.
Debug bool
// Command used to override the server command with the custom one
Command []string `mapstructure:"command"`
// MaxQueueSize is maximum allowed queue size with the pending requests to the workers poll
MaxQueueSize uint64 `mapstructure:"max_queue_size"`
// NumWorkers defines how many sub-processes can be run at once. This value
// might be doubled by Swapper while hot-swap. Defaults to number of CPU cores.
NumWorkers uint64 `mapstructure:"num_workers"`
// MaxJobs defines how many executions is allowed for the worker until
// its destruction. set 1 to create new process for each new task, 0 to let
// worker handle as many tasks as it can.
MaxJobs uint64 `mapstructure:"max_jobs"`
// AllocateTimeout defines for how long pool will be waiting for a worker to
// be freed to handle the task. Defaults to 60s.
AllocateTimeout time.Duration `mapstructure:"allocate_timeout"`
// DestroyTimeout defines for how long pool should be waiting for worker to
// properly destroy, if timeout reached worker will be killed. Defaults to 60s.
DestroyTimeout time.Duration `mapstructure:"destroy_timeout"`
// ResetTimeout defines how long pool should wait before start killing workers
ResetTimeout time.Duration `mapstructure:"reset_timeout"`
// Stream read operation timeout
StreamTimeout time.Duration `mapstructure:"stream_timeout"`
// Supervision config to limit worker and pool memory usage.
Supervisor *SupervisorConfig `mapstructure:"supervisor"`
// Dynamic allocation config
DynamicAllocatorOpts *DynamicAllocationOpts `mapstructure:"dynamic_allocator"`
}
Config .. Pool config Configures the pool behavior.
func (*Config) InitDefaults ¶
func (cfg *Config) InitDefaults()
InitDefaults enables default config values.
type DynamicAllocationOpts ¶ added in v1.1.0
type DynamicAllocationOpts struct {
MaxWorkers uint64 `mapstructure:"max_workers"`
SpawnRate uint64 `mapstructure:"spawn_rate"`
IdleTimeout time.Duration `mapstructure:"idle_timeout"`
}
func (*DynamicAllocationOpts) InitDefaults ¶ added in v1.1.0
func (d *DynamicAllocationOpts) InitDefaults()
type Factory ¶
type Factory interface {
// SpawnWorkerWithContext creates a new WorkerProcess process based on given command with context.
// Process must not be started.
SpawnWorkerWithContext(context.Context, *exec.Cmd, ...worker.Options) (*worker.Process, error)
// Close the factory and underlying connections.
Close() error
}
Factory is responsible for wrapping given command into tasks WorkerProcess.
type SupervisorConfig ¶
type SupervisorConfig struct {
// WatchTick defines how often to check the state of worker.
WatchTick time.Duration `mapstructure:"watch_tick"`
// TTL defines the maximum time for the worker is allowed to live.
TTL time.Duration `mapstructure:"ttl"`
// IdleTTL defines the maximum duration worker can spend in idle mode. Disabled when 0.
IdleTTL time.Duration `mapstructure:"idle_ttl"`
// ExecTTL defines maximum lifetime per job.
ExecTTL time.Duration `mapstructure:"exec_ttl"`
// MaxWorkerMemory limits memory per worker.
MaxWorkerMemory uint64 `mapstructure:"max_worker_memory"`
}
func (*SupervisorConfig) InitDefaults ¶
func (cfg *SupervisorConfig) InitDefaults()
InitDefaults enables default config values.
Click to show internal directories.
Click to hide internal directories.