Skip to content

Commit 6e22035

Browse files
committed
Add upstream keepalive connections cache
1 parent 4235166 commit 6e22035

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

controllers/nginx/configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ The following table shows the options, the default value and a description.
487487
|ssl-session-timeout|10m|
488488
|use-gzip|"true"|
489489
|use-http2|"true"|
490+
|upstream-keepalive-connections|"0" (disabled)|
490491
|variables-hash-bucket-size|64|
491492
|variables-hash-max-size|2048|
492493
|vts-status-zone-size|10m|

controllers/nginx/pkg/config/config.go

+9
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ type Configuration struct {
293293
// Sets the maximum size of the variables hash table.
294294
// http://nginx.org/en/docs/http/ngx_http_map_module.html#variables_hash_max_size
295295
VariablesHashMaxSize int `json:"variables-hash-max-size,omitempty"`
296+
297+
// Activates the cache for connections to upstream servers.
298+
// The connections parameter sets the maximum number of idle keepalive connections to
299+
// upstream servers that are preserved in the cache of each worker process. When this
300+
// number is exceeded, the least recently used connections are closed.
301+
// http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive
302+
// Default: 0 (disabled)
303+
UpstreamKeepaliveConnections int `json:"upstream-keepalive-connections,omitempty"`
296304
}
297305

298306
// NewDefault returns the default nginx configuration
@@ -351,6 +359,7 @@ func NewDefault() Configuration {
351359
WhitelistSourceRange: []string{},
352360
SkipAccessLogURLs: []string{},
353361
},
362+
UpstreamKeepaliveConnections: 0,
354363
}
355364

356365
if glog.V(5) {

controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl

+5
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ http {
235235
{{ $cfg.LoadBalanceAlgorithm }};
236236
{{ end }}
237237
{{ end }}
238+
239+
{{ if (gt $cfg.UpstreamKeepaliveConnections 0) }}
240+
keepalive {{ $cfg.UpstreamKeepaliveConnections }};
241+
{{ end }}
242+
238243
{{ range $server := $upstream.Endpoints }}server {{ $server.Address | formatIP }}:{{ $server.Port }} max_fails={{ $server.MaxFails }} fail_timeout={{ $server.FailTimeout }};
239244
{{ end }}
240245
}

0 commit comments

Comments
 (0)