2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 23:32:17 +08:00

Change default concurrency to the number of CPUs

This commit is contained in:
Ken Hibino 2020-04-18 12:44:52 -07:00
parent 431a96a1f7
commit a0865df33c
2 changed files with 5 additions and 2 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CLI is renamed to `asynq`. - CLI is renamed to `asynq`.
- To upgrade the CLI to the latest version run `go get -u github.com/hibiken/tools/asynq` - To upgrade the CLI to the latest version run `go get -u github.com/hibiken/tools/asynq`
- The `ps` command in CLI is renamed to `servers` - The `ps` command in CLI is renamed to `servers`
- `Concurrency` defaults to the number of CPUs when unset or set to a negative value.
### Added ### Added

View File

@ -11,6 +11,7 @@ import (
"math" "math"
"math/rand" "math/rand"
"os" "os"
"runtime"
"sync" "sync"
"time" "time"
@ -51,7 +52,8 @@ type Server struct {
type Config struct { type Config struct {
// Maximum number of concurrent processing of tasks. // Maximum number of concurrent processing of tasks.
// //
// If set to a zero or negative value, NewServer will overwrite the value to one. // If set to a zero or negative value, NewServer will overwrite the value
// to the number of CPUs usable by the currennt process.
Concurrency int Concurrency int
// Function to calculate retry delay for a failed task. // Function to calculate retry delay for a failed task.
@ -168,7 +170,7 @@ const defaultShutdownTimeout = 8 * time.Second
func NewServer(r RedisConnOpt, cfg Config) *Server { func NewServer(r RedisConnOpt, cfg Config) *Server {
n := cfg.Concurrency n := cfg.Concurrency
if n < 1 { if n < 1 {
n = 1 n = runtime.NumCPU()
} }
delayFunc := cfg.RetryDelayFunc delayFunc := cfg.RetryDelayFunc
if delayFunc == nil { if delayFunc == nil {