Skip to content

Commit 2b6abd3

Browse files
authored
Optimize nginx configuration (#668)
- Add nginx worker_processes - Add upstream section
1 parent f6df5a6 commit 2b6abd3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

helm/openwhisk/templates/nginx-cm.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ metadata:
2424
{{ include "openwhisk.label_boilerplate" . | indent 4 }}
2525
data:
2626
nginx.conf: |
27+
worker_processes {{ .Values.nginx.workerProcesses }};
2728
worker_rlimit_nofile 4096;
2829
2930
events {
@@ -45,6 +46,17 @@ data:
4546
proxy_http_version 1.1;
4647
proxy_set_header Connection "";
4748
49+
upstream controllers {
50+
# Mark the controller as unavailable after fail_timeout seconds, to not get any requests during restart.
51+
# Otherwise, nginx would dispatch requests when the container is up, but the backend in the container not.
52+
# From the docs:
53+
# "normally, requests with a non-idempotent method (POST, LOCK, PATCH) are not passed to
54+
# the next server if a request has been sent to an upstream server"
55+
server {{ include "openwhisk.controller_host" . }}:{{ .Values.controller.port }} fail_timeout=60s;
56+
57+
keepalive 512;
58+
}
59+
4860
server {
4961
listen 80;
5062
listen 443 default ssl;
@@ -72,7 +84,6 @@ data:
7284
7385
# Hack to convince nginx to dynamically resolve the dns entries.
7486
resolver {{ .Values.k8s.dns }};
75-
set $controllers {{ include "openwhisk.controller_host" . }};
7687
{{- if or (eq .Values.whisk.ingress.type "NodePort") (eq .Values.whisk.ingress.type "LoadBalancer") }}
7788
set $apigw {{ include "openwhisk.apigw_host" . }};
7889
{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
@@ -85,12 +96,12 @@ data:
8596
if ($namespace) {
8697
rewrite /(.*) /api/v1/web/${namespace}/$1 break;
8798
}
88-
proxy_pass http://$controllers:{{ .Values.controller.port }};
99+
proxy_pass http://controllers;
89100
proxy_read_timeout 75s; # 70+5 additional seconds to allow controller to terminate request
90101
}
91102

92103
location /api/v1 {
93-
proxy_pass http://$controllers:{{ .Values.controller.port }};
104+
proxy_pass http://controllers;
94105
proxy_read_timeout 75s; # 70+5 additional seconds to allow controller to terminate request
95106
}
96107

@@ -116,7 +127,7 @@ data:
116127
if ($namespace) {
117128
rewrite /(.*) /api/v1/web/${namespace}/$1 break;
118129
}
119-
proxy_pass http://$controllers:{{ .Values.controller.port }};
130+
proxy_pass http://controllers;
120131
proxy_read_timeout 75s; # 70+5 additional seconds to allow controller to terminate request
121132
}
122133

helm/openwhisk/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ nginx:
240240
httpPort: 80
241241
httpsPort: 443
242242
httpsNodePort: 31001
243+
workerProcesses: "auto"
243244
certificate:
244245
external: false
245246
cert_file: ""

0 commit comments

Comments
 (0)