You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/expanded-timeouts.md
+45-33Lines changed: 45 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,11 @@ One of the most common support questions we get is about timeouts. Users often a
8
8
9
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
10
11
+
> For OpenFaaS Edge users should consult the eBook [Serverless For Everyone Else](https://store.openfaas.com/l/serverless-for-everyone-else) and update `docker-compose.yaml`.
12
+
11
13
## Why do functions timeout?
12
14
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.
15
+
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](/reference/async/), so that the HTTP caller is not blocked waiting for a result.
14
16
15
17
Functions timeout due to one of the following:
16
18
@@ -23,58 +25,68 @@ Once you've followed all the instructions in this guide, make sure you've ruled
23
25
24
26
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.
25
27
26
-
## Part 1 - the core components
28
+
The [openfaas helm chart](https://github.com/openfaas/faas-netes/tree/master/chart/openfaas) contains a detailed explanation of values for each OpenFaaS component including timeouts.
29
+
30
+
The most recent versions of OpenFaasS Standard and OpenFaaS For Enterprises, only need timeout values to be applied to the Gateway itself, they are then applied to the operator and built-in queue-worker by default.
31
+
32
+
For dedicated [queue-worker](https://github.com/openfaas/faas-netes/tree/master/chart/queue-worker) installations, you will need to configure their `upstreamTimeout` value separately in values.yaml
27
33
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
34
30
-
You can find the various options in the [helm chart README](https://github.com/openfaas/faas-netes/tree/master/chart/openfaas).
35
+
## Timeout reference
31
36
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).
37
+
The function's `exec_timeout` must always be less than or equal to the gateway's `upstream_timeout`. If the function's timeout is larger than the gateway's, the gateway will cancel the request before the function finishes, resulting in a 502 or timeout error.
33
38
34
-
We need to set the following in the Helm chart's values.yaml file for the OpenFaaS chart:
| Function |`exec_timeout`|`stack.yaml` environment |
45
+
| Function |`read_timeout`|`stack.yaml` environment |
46
+
| Function |`write_timeout`|`stack.yaml` environment |
35
47
36
-
*`gateway.upstreamTimeout`
37
-
*`gateway.writeTimeout`
38
-
*`gateway.readTimeout`
48
+
The function's `exec_timeout` must be equal to or shorter than the gateway's `upstream_timeout`. The gateway's `read_timeout` and `write_timeout` must be slightly longer than `upstream_timeout` to give the gateway time to handle the request cleanly.
39
49
40
-
All timeouts are to be specified in Golang duration format i.e. `1m` or `60s`, or `1m30s`.
50
+
Here is a valid configuration for a function that can run for up to 30 minutes - either synchronously or asynchronously.
41
51
42
-
If using Helm or Argo CD, then add the following to your values.yaml file:
52
+
Gateway (Helm values.yaml):
43
53
44
54
```yaml
45
55
gateway:
46
-
writeTimeout: 5m1s
47
-
readTimeout: 5m1s
48
-
upstreamTimeout: 5m
56
+
upstreamTimeout: 30m
57
+
readTimeout: 30m1s
58
+
writeTimeout: 30m1s
49
59
```
50
60
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:
54
-
55
-
```bash
56
-
export TIMEOUT=5m
57
-
export SERVER_TIMEOUT=5m2s
61
+
Function (stack.yaml):
58
62
59
-
arkade install openfaas \
60
-
--set gateway.upstreamTimeout=$TIMEOUT \
61
-
--set gateway.writeTimeout=$SERVER_TIMEOUT \
62
-
--set gateway.readTimeout=$SERVER_TIMEOUT
63
+
```yaml
64
+
functions:
65
+
my-function:
66
+
environment:
67
+
exec_timeout: 30m
68
+
read_timeout: 30m1s
69
+
write_timeout: 30m1s
63
70
```
64
71
65
-
Once installed with these settings, you can invoke functions for up to `5m` synchronously and asynchronously.
66
-
67
-
## Part 2 - Your function's timeout
72
+
Note: setting `exec_timeout: 10m` on a function when the gateway's `upstream_timeout` is only `5m` will **not** give the function 10 minutes. The gateway will timeout and return an error after 5 minutes.
68
73
69
-
Now that OpenFaaS will allow a longer timeout, configure your function.
74
+
## Configure your function's timeout
70
75
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.
76
+
OpenFaaS functions usually embed a component called the watchdog, which is responsible for implementing timeouts in a consistent way across different languages.
72
77
73
-
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)
78
+
Partial example showing the timeouts:
74
79
75
-
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)
80
+
```yaml
81
+
functions:
82
+
job:
83
+
environment:
84
+
write_timeout: 5m1s
85
+
read_timeout: 5m1s
86
+
exec_timeout: 5m
87
+
```
76
88
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.
89
+
For an example of Node, Python and Golang, see the: [go-long samples](https://github.com/alexellis/go-long).
0 commit comments