Skip to content

Commit

Permalink
Add configuration for worker shutdown timeout (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
domleb authored Mar 14, 2019
1 parent 54b5801 commit 3907a55
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/feed-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const (
defaultNginxWorkingDir = "/nginx"
defaultNginxWorkers = 1
defaultNginxWorkerConnections = 1024
defaultNginxWorkerShutdownTimeoutSeconds = 0
defaultNginxKeepAliveSeconds = 60
defaultNginxBackendKeepalives = 512
defaultNginxBackendTimeoutSeconds = 60
Expand Down Expand Up @@ -170,6 +171,8 @@ func init() {
"Number of nginx worker processes.")
flag.IntVar(&nginxConfig.WorkerConnections, "nginx-worker-connections", defaultNginxWorkerConnections,
"Max number of connections per nginx worker. Includes both client and proxy connections.")
flag.IntVar(&nginxConfig.WorkerShutdownTimeoutSeconds, "nginx-worker-shutdown-timeout-seconds", defaultNginxWorkerShutdownTimeoutSeconds,
"Timeout for a graceful shutdown of worker processes.")
flag.IntVar(&nginxConfig.KeepaliveSeconds, "nginx-keepalive-seconds", defaultNginxKeepAliveSeconds,
"Keep alive time for persistent client connections to nginx. Should generally be set larger than frontend "+
"keep alive times to prevent stale connections.")
Expand Down
1 change: 1 addition & 0 deletions nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Conf struct {
WorkingDir string
WorkerProcesses int
WorkerConnections int
WorkerShutdownTimeoutSeconds int
KeepaliveSeconds int
BackendKeepalives int
BackendConnectTimeoutSeconds int
Expand Down
4 changes: 4 additions & 0 deletions nginx/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pid {{ .WorkingDir }}/nginx.pid;
load_module modules/ngx_http_opentracing_module.so;
{{ end }}

{{ if .WorkerShutdownTimeoutSeconds }}
worker_shutdown_timeout {{ .WorkerShutdownTimeoutSeconds }};
{{ end }}

events {
# Accept connections as fast as possible.
multi_accept on;
Expand Down
18 changes: 18 additions & 0 deletions nginx/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func newConf(tmpDir string, binary string) Conf {
BinaryLocation: binary,
Ports: []Port{{Name: "http", Port: port}},
WorkerProcesses: 1,
WorkerShutdownTimeoutSeconds: 0,
BackendKeepalives: 1024,
BackendConnectTimeoutSeconds: 1,
ServerNamesHashMaxSize: -1,
Expand Down Expand Up @@ -224,6 +225,9 @@ func TestNginxConfig(t *testing.T) {
incorrectLargeClientHeaderBufferConf := defaultConf
incorrectLargeClientHeaderBufferConf.LargeClientHeaderBufferBlocks = 4

workerShutdowntimeoutConf := defaultConf
workerShutdowntimeoutConf.WorkerShutdownTimeoutSeconds = 10

var tests = []struct {
name string
conf Conf
Expand Down Expand Up @@ -408,6 +412,20 @@ func TestNginxConfig(t *testing.T) {
"!large_client_header_buffers",
},
},
{
"Worker shutdown timeout setting not present if default",
defaultConf,
[]string{
"!worker_shutdown_timeout",
},
},
{
"Worker shutdown timeout is present if not set to default",
workerShutdowntimeoutConf,
[]string{
"worker_shutdown_timeout 10;",
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 3907a55

Please sign in to comment.