Skip to content

Commit 56b73a3

Browse files
committed
Additional information on nginx for longer timeouts
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent db8ca4d commit 56b73a3

File tree

4 files changed

+57
-25
lines changed

4 files changed

+57
-25
lines changed

docs/reference/async.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ The queue-worker uses a single timeout for how long it will spend processing a m
120120
121121
By default there is one queue-worker replica deployed which is set up to run a single task of up to 30 seconds in duration.
122122

123-
You can increase the parallelism by setting the queue worker's "max_inflight" option to a value greater than one. This will cause the queue-worker to concurrently receive up to max_inflight many messages and simultaneously invoke their corresponding functions. Should you wish to restrict concurrency for certain functions, please make use of [multiple queues](#Multiple-queues) and separate these functions accordingly.
123+
You can increase the parallelism by setting the queue worker's "max_inflight" option to a value greater than one. This will cause the queue-worker to concurrently receive up to max_inflight many messages and simultaneously invoke their corresponding functions. Should you wish to restrict concurrency for certain functions, please make use of [dedicated queues](#dedicated-queues) and separate these functions accordingly.
124124

125125
Additional replicas of the queue-worker can also be added, such that the total async concurrency for a cluster will be: max_inflight * (number of queue-worker replicas).
126126

docs/reference/tls-openfaas.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ $ arkade install ingress-nginx
3636

3737
See also: [ingress-nginx installation](https://kubernetes.github.io/ingress-nginx/deploy/)
3838

39+
40+
#### Timeouts for synchronous invocations
41+
42+
Despite configuring OpenFaaS and your functions for [extended timeouts](/tutorials/expanded-timeouts.md), you may find that your Ingress Controller, Istio Gateway, or Cloud Load Balancer implements its own timeouts on connections. If you think you have everything configured correctly for OpenFaaS, but see a timeout at a very specific number such as 30s or 60s, then check the timeouts on your Ingress Controller or Load Balancer.
43+
44+
For Ingress Nginx, to extend a synchronous invocation beyond one minute, add the `nginx.ingress.kubernetes.io/proxy-read-timeout` annotation to your Ingress resource. This annotation is specified in seconds - for example, to extend the timeout to 30 minutes, use `nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"`.
45+
3946
### Install cert-manager
4047

4148
cert-manager is a Kubernetes operator maintained by the Cloud Native Computing Foundation (CNCF) which automates TLS certificate management.
@@ -125,13 +132,15 @@ You can now configure the OpenFaaS gateway to use TLS by setting the following H
125132

126133
```sh
127134
export DOMAIN="gw.example.com"
135+
export NGINX_TIMEOUT_SECS="1800" # 30 minutes
128136

129137
cat > tls.yaml <<EOF
130138
ingress:
131139
enabled: true
132140
ingressClassName: nginx
133141
annotations:
134142
cert-manager.io/issuer: letsencrypt-prod
143+
nginx.ingress.kubernetes.io/proxy-read-timeout: "$NGINX_TIMEOUT_SECS"
135144
tls:
136145
- hosts:
137146
- $DOMAIN
@@ -173,13 +182,15 @@ Edit the previous example:
173182
```sh
174183
export DOMAIN="gw.example.com"
175184
export DOMAIN_DASHBOARD="dashboard.example.com"
185+
export NGINX_TIMEOUT_SECS="1800" # 30 minutes
176186

177187
cat > tls.yaml <<EOF
178188
ingress:
179189
enabled: true
180190
ingressClassName: nginx
181191
annotations:
182192
cert-manager.io/issuer: letsencrypt-prod
193+
nginx.ingress.kubernetes.io/proxy-read-timeout: "$NGINX_TIMEOUT_SECS"
183194
tls:
184195
- hosts:
185196
- $DOMAIN

docs/tutorials/expanded-timeouts.md

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,80 @@
1-
# Expanded timeouts
1+
# Extended timeouts
22

3-
In this tutorial you'll learn how to expand the default timeouts of OpenFaaS to run your functions for longer.
3+
In this tutorial you'll learn how to extend the default timeout so that your functions can run for longer.
4+
5+
One of the most common support questions we get is about timeouts. Users often ask why their function is timing out after 30s or 60s.
46

57
!!! note "It's not us, it's you."
68

7-
We would know if there was a regression in OpenFaaS that meant timeouts stopped working as expected.
9+
We know it's frustrating, but we would know if there was a regression in OpenFaaS that meant timeouts stopped working as expected.
10+
11+
## Why do functions timeout?
12+
13+
OpenFaaS functions can run for as long as necessary, some users have reported running executions for 48 hours or longer. The longest executions should be [run asynchronously](), so that the HTTP caller is not blocked waiting for a result.
14+
15+
Functions timeout due to one of the following:
816

9-
Typically, every time users reach out to us for help with timeouts it's due to a misconfiguration between one of the components in their stack, or a problem with the function itself.
17+
* Using the default timeout set in the Helm chart in values.yaml for the gateway
18+
* Using the default timeout in the Function's stack.yaml, or not setting all of the timeout environment variables
19+
* An error in the function's code - a blocking I/O operation, a deadlock, or a crash/premature exit of the process
20+
* Using an Ingress Controller or Load Balancer which has a low default timeout
1021

11-
You will need to use our sample functions, which we know work, before reaching out for support.
22+
Once you've followed all the instructions in this guide, make sure you've ruled out your Ingress Controller or Load Balancer before reaching out for help. For instance, [Ingress Nginx has a timeout set of 60 seconds](#load-balancers-ingress-and-service-meshes).
23+
24+
You can use the [following GitHub repository](https://github.com/alexellis/go-long) with three sample functions made with Go, Python and Node to confirm the issue isn't in your own function or code.
1225

1326
## Part 1 - the core components
1427

15-
When running OpenFaaS on Kubernetes, you need to set various timeout values for the distributed components of the OpenFaaS control plane. These options are explained in the [helm chart README](https://github.com/openfaas/faas-netes/tree/master/chart/openfaas). The easiest option for new users is to set them all to the same value.
28+
When running OpenFaaS on Kubernetes, it is possible to override the timeout on various components of the OpenFaaS gateway, however it is only usually necessary to set the timeout on the gateway itself.
29+
30+
You can find the various options in the [helm chart README](https://github.com/openfaas/faas-netes/tree/master/chart/openfaas).
1631

17-
> For faasd users, you'll need to edit the equivalent fields in your `docker-compose.yaml` file, see the eBook [Serverless For Everyone Else](https://store.openfaas.com/l/serverless-for-everyone-else).
32+
For faasd users, you'll need to edit the equivalent fields in your `docker-compose.yaml` file, see the eBook [Serverless For Everyone Else](https://store.openfaas.com/l/serverless-for-everyone-else).
1833

19-
We will set:
34+
We need to set the following in the Helm chart's values.yaml file for the OpenFaaS chart:
2035

2136
* `gateway.upstreamTimeout`
2237
* `gateway.writeTimeout`
2338
* `gateway.readTimeout`
2439

2540
All timeouts are to be specified in Golang duration format i.e. `1m` or `60s`, or `1m30s`.
2641

27-
The `HARD_TIMEOUT` is set 1-2s higher than the `TIMEOUT` value since one needs to happen before the other.
42+
If using Helm or Argo CD, then add the following to your values.yaml file:
43+
44+
```yaml
45+
gateway:
46+
writeTimeout: 5m1s
47+
readTimeout: 5m1s
48+
upstreamTimeout: 5m
49+
```
50+
51+
Note that `upstreamTimeout` must always be lower than `writeTimeout` and `readTimeout`, to allow the gateway to handle the request before the HTTP server cancels the request.
52+
53+
If using arkade, you can run the following:
2854

2955
```bash
3056
export TIMEOUT=5m
31-
export HARD_TIMEOUT=5m2s
57+
export SERVER_TIMEOUT=5m2s
3258
3359
arkade install openfaas \
3460
--set gateway.upstreamTimeout=$TIMEOUT \
35-
--set gateway.writeTimeout=$HARD_TIMEOUT \
36-
--set gateway.readTimeout=$HARD_TIMEOUT
61+
--set gateway.writeTimeout=$SERVER_TIMEOUT \
62+
--set gateway.readTimeout=$SERVER_TIMEOUT
3763
```
3864

3965
Once installed with these settings, you can invoke functions for up to `5m` synchronously and asynchronously.
4066

41-
If using Helm or Argo CD, then add the following to your values.yaml file instead:
42-
43-
```yaml
44-
gateway:
45-
writeTimeout: 5m1s
46-
readTimeout: 5m1s
47-
upstreamTimeout: 5m
48-
```
49-
5067
## Part 2 - Your function's timeout
5168

5269
Now that OpenFaaS will allow a longer timeout, configure your function.
5370

71+
OpenFaaS functions usually embed a component called the watchdog, which is responsible for implementing timeouts in a consistent way across different languages. Most templates use the newer of-watchdog, but a few may still be using the classic watchdog for compatibility reasons.
72+
5473
For the newer templates based upon HTTP which use the of-watchdog, adapt the following sample: [go-long: Golang function that runs for a long time](https://github.com/alexellis/go-long)
5574

5675
For classic templates using the classic watchdog, you can follow the workshop: [Lab 8 - Advanced feature - Timeouts](https://github.com/openfaas/workshop/blob/master/lab8.md)
5776

58-
If you're unsure which template you're using, check the source code of the Dockerfile in the `templates` folder when you build your functions.
77+
If you're unsure which template you're using, check the source code of the Dockerfile in the `templates` folder when you build your functions, you should see a `FROM` line at the top of the file that will specify one or the other.
5978

6079
## Load Balancers, Ingress, and service meshes
6180

@@ -67,7 +86,9 @@ AWS EKS is configured to use an [Elastic Load Balancer (ELB)](https://aws.amazon
6786

6887
Google Cloud's various Load Balancer options have their [own configuration options too](https://cloud.google.com/load-balancing/docs/https).
6988

70-
Finally, if you need to invoke a function for longer than one of your infrastructure components allows, then you should use an [asynchronous invocation](/reference/async), which in OpenFaaS Standard can also be retried if it fails, and scaled out to massive concurrency.
89+
For Ingress Nginx, set the `nginx.ingress.kubernetes.io/proxy-read-timeout` annotation to extend the timeout. This annotation is specified in seconds - for example, to extend the timeout to 30 minutes, use `nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"`.
90+
91+
Finally, if you need to invoke a function for longer than one of your infrastructure components allows, then you should use an [asynchronous invocation](/reference/async). Asynchronous function invocations bypass these components because they are eventually invoked from the queue-worker, not the Internet. The queue-worker for OpenFaaS Standard will also retry invocations if required.
7192
7293
## Further support
7394

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ nav:
203203
- Training:
204204
- Overview: ./tutorials/training.md
205205
- Tutorials:
206-
- Expanded timeouts: ./tutorials/expanded-timeouts.md
206+
- Extended timeouts: ./tutorials/expanded-timeouts.md
207207
- CLI with Node.js: ./tutorials/CLI-with-node.md
208208
- First Python Function: ./tutorials/first-python-function.md
209209
- Local Ingress with KinD: ./tutorials/local-kind-ingress.md

0 commit comments

Comments
 (0)