From 816f6a8e07c3aabc7681beaa609b6a16d34dec2c Mon Sep 17 00:00:00 2001 From: DarthSim Date: Thu, 28 Sep 2017 23:17:23 +0600 Subject: [PATCH] More reasonable defaults --- README.md | 4 ++-- config.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dc14ff16..19943d12 100644 --- a/README.md +++ b/README.md @@ -135,8 +135,8 @@ $ xxd -g 2 -l 64 -p /dev/random | tr -d '\n' * `IMGPROXY_READ_TIMEOUT` — the maximum duration (in seconds) for reading the entire image request, including the body. Default: `10`; * `IMGPROXY_WRITE_TIMEOUT` — the maximum duration (in seconds) for writing the response. Default: `10`; * `IMGPROXY_DOWNLOAD_TIMEOUT` — the maximum duration (in seconds) for downloading the source image. Default: `5`; -* `IMGPROXY_CONCURRENCY` — the maximum number of image requests to be processed simultaneously. Default: `100`; -* `IMGPROXY_MAX_CLIENTS` — the maximum number of simultaneous active connections. Default: `IMGPROXY_CONCURRENCY * 2`; +* `IMGPROXY_CONCURRENCY` — the maximum number of image requests to be processed simultaneously. Default: double number of CPU cores; +* `IMGPROXY_MAX_CLIENTS` — the maximum number of simultaneous active connections. Default: `IMGPROXY_CONCURRENCY * 5`; #### Security diff --git a/config.go b/config.go index 0b103b89..d64285d7 100644 --- a/config.go +++ b/config.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "log" "os" + "runtime" "strconv" ) @@ -83,7 +84,7 @@ var conf = config{ ReadTimeout: 10, WriteTimeout: 10, DownloadTimeout: 5, - Concurrency: 100, + Concurrency: runtime.NumCPU() * 2, TTL: 3600, MaxSrcDimension: 4096, Quality: 80, @@ -145,7 +146,7 @@ func init() { } if conf.MaxClients <= 0 { - conf.MaxClients = conf.Concurrency * 2 + conf.MaxClients = conf.Concurrency * 5 } if conf.TTL <= 0 {