Expanded timeouts

In this tutorial you’ll learn how to expand the default timeouts of OpenFaaS to run your functions for longer.

Part 1 - the core components

When installing with 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. The easiest option for new users is to set them all to the same value.

We will set:

  • gateway.upstreamTimeout
  • gateway.writeTimeout
  • gateway.readTimeout
  • faasnetes.writeTimeout
  • faasnetes.readTimeout

For async tasks, also set:

  • queueWorker.ackWait

All timeouts are to be specified in Golang duration format i.e. 1m or 12s, or 1m12s.

  1. export TIMEOUT=2m
  2. arkade install openfaas \
  3. --set gateway.upstreamTimeout=$TIMEOUT \
  4. --set gateway.writeTimeout=$TIMEOUT \
  5. --set gateway.readTimeout=$TIMEOUT \
  6. --set faasnetes.writeTimeout=$TIMEOUT \
  7. --set faasnetes.readTimeout=$TIMEOUT \
  8. --set queueWorker.ackWait=$TIMEOUT

One installed with these settings, you can invoke functions for up to 2m synchronously and asynchronously.

Part 2 - Your function’s timeout

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

For classic templates using the classic watchdog, you can follow the workshop: Lab 8 - Advanced feature - Timeouts

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

Further support

Check the troubleshooting guide and work through the exercises above.

For Docker Swarm, simply edit docker-compose.yml and redeploy the stack.