From bb3a9c77f7fd9c63409d33c0ff74134b87f3ae2b Mon Sep 17 00:00:00 2001 From: DarthSim Date: Tue, 19 Jul 2022 18:04:22 +0600 Subject: [PATCH] Set default IMGPROXY_MAX_CLIENTS value to 2048; Allow unlimited connections --- config/config.go | 6 +++--- docs/configuration.md | 2 +- server.go | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 312e47d6..1a3c32d8 100644 --- a/config/config.go +++ b/config/config.go @@ -186,7 +186,7 @@ func Reset() { KeepAliveTimeout = 10 DownloadTimeout = 5 Concurrency = runtime.NumCPU() * 2 - MaxClients = 0 + MaxClients = 2048 TTL = 3600 CacheControlPassthrough = false @@ -534,8 +534,8 @@ func Configure() error { return fmt.Errorf("Concurrency should be greater than 0, now - %d\n", Concurrency) } - if MaxClients <= 0 { - MaxClients = Concurrency * 10 + if MaxClients < 0 { + return fmt.Errorf("Concurrency should be greater than or equal 0, now - %d\n", MaxClients) } if TTL <= 0 { diff --git a/docs/configuration.md b/docs/configuration.md index 6828555f..e1abbc54 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -33,7 +33,7 @@ echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n') * `IMGPROXY_KEEP_ALIVE_TIMEOUT`: the maximum duration (in seconds) to wait for the next request before closing the connection. When set to `0`, keep-alive is disabled. 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: the number of CPU cores multiplied by two -* `IMGPROXY_MAX_CLIENTS`: the maximum number of simultaneous active connections. Default: `IMGPROXY_CONCURRENCY * 10` +* `IMGPROXY_MAX_CLIENTS`: the maximum number of simultaneous active connections. When set to `0`, connections number limitation is disabled. Default: `2048` * `IMGPROXY_TTL`: a duration (in seconds) sent via the `Expires` and `Cache-Control: max-age` HTTP headers. Default: `3600` (1 hour) * `IMGPROXY_CACHE_CONTROL_PASSTHROUGH`: when `true` and the source image response contains the `Expires` or `Cache-Control` headers, reuse those headers. Default: false * `IMGPROXY_SET_CANONICAL_HEADER`: when `true` and the source image has an `http` or `https` scheme, set a `rel="canonical"` HTTP header to the value of the source image URL. More details [here](https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls#rel-canonical-header-method). Default: `false` diff --git a/server.go b/server.go index a9298daf..ee660106 100644 --- a/server.go +++ b/server.go @@ -45,7 +45,10 @@ func startServer(cancel context.CancelFunc) (*http.Server, error) { if err != nil { return nil, fmt.Errorf("Can't start server: %s", err) } - l = netutil.LimitListener(l, config.MaxClients) + + if config.MaxClients > 0 { + l = netutil.LimitListener(l, config.MaxClients) + } s := &http.Server{ Handler: buildRouter(),