diff options
author | Valery Piashchynski <[email protected]> | 2020-10-19 14:01:59 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-10-19 14:01:59 +0300 |
commit | 77670fb7af0c892c9b3a589fd424534fad288e7a (patch) | |
tree | 3adcaa85db664a355abe2b28f1d7e4a3fc45689f /pool.go | |
parent | 16fbf3104c3c34bd9355593052b686acd26a8efe (diff) |
Update according activity worker
Diffstat (limited to 'pool.go')
-rw-r--r-- | pool.go | 49 |
1 files changed, 13 insertions, 36 deletions
@@ -2,7 +2,6 @@ package roadrunner import ( "context" - "fmt" "runtime" "time" ) @@ -47,7 +46,9 @@ type Pool interface { Events() chan PoolEvent // Exec one task with given payload and context, returns result or error. - Exec(ctx context.Context, rqs Payload) (Payload, error) + ExecWithContext(ctx context.Context, rqs Payload) (Payload, error) + + Exec(rqs Payload) (Payload, error) // Workers returns worker list associated with the pool. Workers() (workers []WorkerBase) @@ -66,7 +67,7 @@ type Pool interface { // type Config struct { // NumWorkers defines how many sub-processes can be run at once. This value - // might be doubled by Swapper while hot-swap. + // might be doubled by Swapper while hot-swap. Defaults to number of CPU cores. NumWorkers int64 // MaxJobs defines how many executions is allowed for the worker until @@ -75,17 +76,17 @@ type Config struct { MaxJobs int64 // AllocateTimeout defines for how long pool will be waiting for a worker to - // be freed to handle the task. + // be freed to handle the task. Defaults to 60s. AllocateTimeout time.Duration // DestroyTimeout defines for how long pool should be waiting for worker to - // properly destroy, if timeout reached worker will be killed. + // properly destroy, if timeout reached worker will be killed. Defaults to 60s. DestroyTimeout time.Duration // TTL defines maximum time worker is allowed to live. TTL int64 - // IdleTTL defines maximum duration worker can spend in idle mode. + // IdleTTL defines maximum duration worker can spend in idle mode. Disabled when 0. IdleTTL int64 // ExecTTL defines maximum lifetime per job. @@ -94,45 +95,21 @@ type Config struct { // MaxPoolMemory defines maximum amount of memory allowed for worker. In megabytes. MaxPoolMemory uint64 + // MaxWorkerMemory limits memory per worker. MaxWorkerMemory uint64 - - // config from limit plugin, combine TODO - // single bootstrap TODO, bool - // warmup one worker and start consume requests and then start the rest of the stack - - // max memory for pool - // max ttl - // max idle ttl - - // ATTACHER interface - delete -} - -// InitDefaults allows to init blank config with pre-defined set of default values. -func (cfg *Config) InitDefaults() error { - cfg.AllocateTimeout = time.Minute - cfg.DestroyTimeout = time.Minute - cfg.NumWorkers = int64(runtime.NumCPU()) - - return nil } -// Valid returns error if config not valid. -func (cfg *Config) Valid() error { +// InitDefaults enables default config values. +func (cfg *Config) InitDefaults() { if cfg.NumWorkers == 0 { - return fmt.Errorf("pool.NumWorkers must be set") + cfg.NumWorkers = int64(runtime.NumCPU()) } if cfg.AllocateTimeout == 0 { - return fmt.Errorf("pool.AllocateTimeout must be set") + cfg.AllocateTimeout = time.Minute } if cfg.DestroyTimeout == 0 { - return fmt.Errorf("pool.DestroyTimeout must be set") + cfg.DestroyTimeout = time.Minute } - - if cfg.ExecTTL == 0 { - return fmt.Errorf("pool.ExecTTL must be set") - } - - return nil } |