1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-23 11:14:48 +02:00

Add IMGPROXY_KEEP_ALIVE_TIMEOUT config

This commit is contained in:
DarthSim 2019-06-21 16:32:37 +06:00
parent e894afec13
commit 8517402e7e
3 changed files with 20 additions and 8 deletions

View File

@ -130,8 +130,8 @@ func presetFileConfig(p presets, filepath string) {
type config struct {
Bind string
ReadTimeout int
WaitTimeout int
WriteTimeout int
KeepAliveTimeout int
DownloadTimeout int
Concurrency int
MaxClients int
@ -211,6 +211,7 @@ var conf = config{
Bind: ":8080",
ReadTimeout: 10,
WriteTimeout: 10,
KeepAliveTimeout: 10,
DownloadTimeout: 5,
Concurrency: runtime.NumCPU() * 2,
TTL: 3600,
@ -250,6 +251,7 @@ func configure() {
strEnvConfig(&conf.Bind, "IMGPROXY_BIND")
intEnvConfig(&conf.ReadTimeout, "IMGPROXY_READ_TIMEOUT")
intEnvConfig(&conf.WriteTimeout, "IMGPROXY_WRITE_TIMEOUT")
intEnvConfig(&conf.KeepAliveTimeout, "IMGPROXY_KEEP_ALIVE_TIMEOUT")
intEnvConfig(&conf.DownloadTimeout, "IMGPROXY_DOWNLOAD_TIMEOUT")
intEnvConfig(&conf.Concurrency, "IMGPROXY_CONCURRENCY")
intEnvConfig(&conf.MaxClients, "IMGPROXY_MAX_CLIENTS")
@ -362,6 +364,9 @@ func configure() {
if conf.WriteTimeout <= 0 {
logFatal("Write timeout should be greater than 0, now - %d\n", conf.WriteTimeout)
}
if conf.KeepAliveTimeout < 0 {
logFatal("KeepAlive timeout should be greater than or equal to 0, now - %d\n", conf.KeepAliveTimeout)
}
if conf.DownloadTimeout <= 0 {
logFatal("Download timeout should be greater than 0, now - %d\n", conf.DownloadTimeout)

View File

@ -29,6 +29,7 @@ $ echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')
* `IMGPROXY_BIND`: TCP address and port to listen on. Default: `:8080`;
* `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_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: number of CPU cores times two;
* `IMGPROXY_MAX_CLIENTS`: the maximum number of simultaneous active connections. Default: `IMGPROXY_CONCURRENCY * 10`;

View File

@ -42,6 +42,12 @@ func startServer() *http.Server {
MaxHeaderBytes: 1 << 20,
}
if conf.KeepAliveTimeout > 0 {
s.IdleTimeout = time.Duration(conf.KeepAliveTimeout) * time.Second
} else {
s.SetKeepAlivesEnabled(false)
}
initProcessingHandler()
go func() {