queue-worker

by Helm

Helm chartv0.2.35

Dedicated queue-worker for OpenFaaS using JetStream

About this chart

JetStream for OpenFaaS queue-worker

Use this chart to deploy additional queues and queue-workers, for functions which need to be separated out from the default queue.

Note: This chart requires OpenFaaS for Enterprises. Please reach out to us to discuss upgrading your installation.

Reasons why you may want an additional queue-worker:

  • You run workloads for your own product, and for tenants, and want to separate the two
  • You want to run some queues with different settings, such as maxInflight (perhaps a function has a specific amount of requests it can handle at once), upstreamTimeout (longer timeouts), mode (static/function based consumers)
  • Certain long-running invocations may "clog up" the queue and starve requests from other functions, so you want to run those separately

Install an additional queue-worker

helm upgrade --install \
  slow-fns openfaas/queue-worker \
  --namespace openfaas \
  --set maxInflight=5 \
  --set mode=static \
  --set nats.stream.name=slow-fns \
  --set nats.consumer.durableName=slow-fns-workers \
  --set upstreamTimeout=15m

It's recommended to take the NAME of the queue i.e. slow-fns and then use it as prefix in the following way for the above configuration:

  • nats.stream.name - NAME-requests
  • nats.consumer.durableName - NAME-workers

As an alternative to using --set, you could also write your own YAML file. Below is the equivalent configuration in a values.yaml file, for instance values-slow-fns.yaml:

maxInflight: 5
mode: static
nats:
  stream:
    name: slow-fns
  consumer:
    durableName: slow-fns-workers
upstreamTimeout: 15m 

Then pass -f ./values-slow-fns.yaml to the helm upgrade --install command instead of the --set flags.

The chart will append a suffix of -queue-worker to the release name given above, so the name of the queue-worker will be slow-fns-queue-worker.

Upon start-up, the queue-worker will create a NATS JetStream stream named slow-fns. Depending on the queue mode either one static consumer will be created, or if the mode is set to function, a consumer will be created for each function that has invocations pending.

Remember to set the com.openfaas.queue annotation for your functions, so that their requests get submitted to the correct queue (NATS JetStream Stream).

For example:

# Runs on the slow queue
faas-cli store deploy sleep --name slow-fn --annotation com.openfaas.queue=slow-fns

faas-cli invoke --async slow-fn <<< ""

# Runs on the default queue
faas-cli store deploy env --name fast-fn

faas-cli invoke --async fast-fn <<< ""

To remove a queue-worker, run:

helm uninstall --namespace openfaas \
  slow-fns

Install a development version of the chart

The below instructions are for development on the chart itself, or if you want to test changes to the chart's templates that have not yet been released.

Checkout the code, and cd to the folder:

git clone https://github.com/openfaas/faas-netes --depth=1
cd faas-netes/chart/queue-worker
helm upgrade --install \
  slow-fns ./ \
  --namespace openfaas \
  --set maxInflight=5 \
  --set mode=static \
  --set nats.stream.name=slow-fns \
  --set nats.consumer.durableName=slow-fns-workers \
  --set upstreamTimeout=15m

Configuration

ParameterDescriptionDefault
imageThe queue-worker image that should be deployedSee values.yaml
replicasNumber of queue-worker replicas to create1
queueNameName of the queue if you want it to be different to the stream name"" - when empty, defaults to nats.stream.name
modeQueue operation mode: static (OpenFaaS Standard) or function (requires OpenFaaS for Enterprises)static
maxInflightControl the concurrent invocations1
adaptiveConcurrencyEnable adaptive concurrency limiting for functions. This setting only takes effect when mode is set to function.true
queuePartitionsNumber of queue partitions1
partitionQueue partition number this queue should subscribe to0
consumer.inactiveThresholdIf a function is inactive (has no invocations) for longer than this threshold its consumer will be removed to save resources30s
consumer.pullMaxMessagesPullMaxMessages limits the number of messages to be buffered per consumer. Leave empty to use optimized default for the selected queue mode``
upstreamTimeoutMaximum duration of upstream function call1m
maxRetryAttemptsThe amount of times to try sending a message to a function before discarding it10
maxRetryWaitThe maximum amount of time to wait between retries120s
initialRetryWaitThe amount of time to wait for the first retry10s
httpRetryCodesA comma-separated list of HTTP status codes which the queue worker will retry when received from a function408,429,500,502,503,504
backoffThe backoff algorithm used for retries. Must be one off exponential, full or equalexponential
gateway.hostThe host at which the OpenFaaS gateway can be reachedhttp://gateway.openfaas
gateway.portThe port at which the OpenFaaS gateway can be reached8080
insecureTLSEnable insecure tls for callbacksfalse
allowedCallbackURLsList of glob patterns for URLs allowed to receive async callbacks. Defaults to ["*"] (allow all). Set to empty list [] to deny all["*"]
nats.hostThe host at which the NATS JetStream server can be reachednats.openfaas
nats.portThe port at which the NATS JetStream server can be reached4222
nats.stream.nameName of the NATS JetStream stream to usefaas-request
nats.stream.replicasNumber of JetStream stream replicas to create1
nats.consumer.durableNameThe name of the NATS JetStream consumer to usefaas-workers
nats.consumer.ackWaitDo not change from 30s. Only gateway.upstreamTimeout sets the maximum function duration. See Async reference30s
logs.debugPrint debug logsfalse
logs.formatThe log encoding format. Supported values: json or consoleconsole
resources.requests.memoryMemory resource request120Mi
resources.requests.cpuCPU resource request50m
imagePullPolicyImage pull policyIfNotPresent
nodeSelectorNodeSelector for deployment{}
tolerationsTolerations for deployment[]
affinityAaffinity rules for deployment{}

Deploy queue-worker with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has queue-worker on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartqueue-worker is pinned at v0.2.35 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply