Skip to content

Commit 5858cd0

Browse files
committed
Rename Queue Worker page and explain Queue-based scaling
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 7a1b1f7 commit 5858cd0

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

docs/openfaas-pro/jetstream.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
# JetStream for OpenFaaS
1+
# Queue Worker
22

3-
The OpenFaaS async system used to be powered by NATS Streaming. The new generation of the [OpenFaaS async system](/reference/async) is backed by NATS JetStream.
3+
The Queue Worker is a batteries-included, scale-out queue for invoking functions asynchronously.
44

5-
> Note: This feature is included for [OpenFaaS Standard & For Enterprises](https://openfaas.com/pricing/) customers.
5+
This page is primarily concerned with how to configure the Queue Worker, you can learn about [asynchronous invocations here](/reference/async).
66

7+
> Note: This feature is included for [OpenFaaS Standard & For Enterprises](https://openfaas.com/pricing/) customers.
78
89
## Async use cases
910

10-
Async can be used for any OpenFaaS function invocation, where the response is not required immediately, but is either discarded or made available at a later time. Some use-cases include:
11+
Every function in OpenFaaS can be invoked either synchronously or asynchronously. Asynchronous invocations are retried automatically, and can return their response to a given endpoint via a webhook.
12+
13+
Popular use-cases include:
1114

1215
- Batch processing and machine learning
1316
- Resilient data pipelines
1417
- Receiving webhooks
1518
- Long running jobs
1619

17-
On our blog we demo and explore some architectural patterns for these uses cases:
20+
On the blog we show reference examples built upon these architectural patterns:
1821

1922
- [Exploring the Fan out and Fan in pattern with OpenFaaS](https://www.openfaas.com/blog/fan-out-and-back-in-using-functions/)
2023
- [Generate PDFs at scale on Kubernetes using OpenFaaS and Puppeteer](https://www.openfaas.com/blog/pdf-generation-at-scale-on-kubernetes/)
@@ -23,14 +26,15 @@ On our blog we demo and explore some architectural patterns for these uses cases
2326

2427
## Terminology
2528

26-
In JetStream ("js" for short), there are new terms that will help us all in running and debugging the product.
29+
* NATS - an open source messaging system hosted by the [CNCF](https://www.cncf.io/)
30+
* NATS JetStream - a messaging system built on top of NATS for durable queues and message streams
2731

28-
1. A JetStream Server is the original NATS Core project, running in "jetstream mode"
29-
2. A Stream is a message store it is used in OpenFaaS to queue async invocation messages.
30-
3. A Consumer is a stateful view of a stream when clients consume messages from a stream the consumer keeps track of which messages were delivered and acknowledged.
31-
5. A Subscriber is what the queue-worker creates to start pulling messages from the stream. If the max_inflight is set to 25, the queue-worker will pull a maximum of 25 messages at a time.
32+
1. A JetStream Server is the NATS server, running in *jetstream* mode
33+
2. A Stream is a message store it is used in OpenFaaS to queue async invocation messages.
34+
3. A Consumer is a stateful view of a stream when clients consume messages from a stream the consumer keeps track of which messages were delivered and acknowledged.
35+
5. A Subscriber is what the queue-worker creates to start pulling messages from the stream.
3236

33-
> You can learn more about JetStream here: [Docs for JetStream](https://docs.nats.io/nats-concepts/jetstream)
37+
Learn more about [NATS JetStream](https://docs.nats.io/nats-concepts/jetstream)
3438

3539
## Installation
3640

@@ -44,9 +48,13 @@ nats:
4448
streamReplication: 1
4549
```
4650
47-
If the NATS pod restarts, you will lose all messages that it contains. In your development or staging environment, this shouldn't happen very often.
51+
If the NATS Pod restarts, you will lose all messages that it contains. In your development or staging environment. This could happen if you update the chart and the version of the NATS server has changed, or if a node is removed from the cluster.
52+
53+
For production environments you should install NATS separately using its Helm chart.
54+
55+
NATS can be configured with a quorum of at least 3 replicas so it can recover data if one of the replicas should crash. You can also enable a persistent volume in the NATS chart for additional durability.
4856
49-
For production environments you will need to install NATS separately using its Helm chart with at least 3 server replicas, so that if a pod crashes, the data can be recovered automatically.
57+
If you are running with 3 replicas of the NATS server, then update the OpenFaaS chart to reflect that in the `nats.streamReplication` parameter. With this in place, the stream for queued messages will be replicated across the 3 NATS servers.
5058

5159
```yaml
5260
queueMode: jetstream
@@ -58,8 +66,31 @@ nats:
5866
port: "4222"
5967
```
6068

69+
By default the NATS helm chart will be installed into the nats namespace with the name of `nats`, but you can customise this if you wish by setting the `nats.external.host` parameter.
70+
6171
## Features
6272

73+
### Queue-based scaling for functions
74+
75+
The queue-worker uses a shared NATS Stream and NATS Consumer by default, which works well with many of the existing [autoscaling strategies](/reference/async/#autoscaling).
76+
77+
However, if you wish to scales functions based upon the queue depth for each, you can set up the queue-worker to scale its NATS Consumers dynamically for each function.
78+
79+
```yaml
80+
jetstreamQueueWorker:
81+
mode: static | function
82+
consumer:
83+
inactiveThreshold: 30s
84+
```
85+
86+
The `mode` parameter can be set to `static` or `function`.
87+
88+
If set to `static`, the queue-worker will scale its NATS Consumers based upon the number of replicas of the queue-worker. This is the default mode, and ideal for development, or constrained environments.
89+
90+
If set to `function`, the queue-worker will scale its NATS Consumers based upon the number of functions that are active in the queue. This is ideal for production environments where you want to scale your functions based upon the queue depth. It also gives messages queued at different times a fairer chance of being processed earlier.
91+
92+
The `inactiveThreshold` parameter can be used to set the threshold for when a function is considered inactive. If a function is inactive for longer than the threshold, the queue-worker will delete the NATS Consumer for that function.
93+
6394
### Metrics and monitoring
6495

6596
Get insight into the behaviour of your queues with built in metrics.

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ nav:
160160
- Okta: ./openfaas-pro/sso/okta.md
161161
- SSO with the CLI: ./openfaas-pro/sso/cli.md
162162
- Function CRD: ./openfaas-pro/function-crd.md
163-
- JetStream: ./openfaas-pro/jetstream.md
163+
- Queue Worker: ./openfaas-pro/jetstream.md
164164
- Kafka events: ./openfaas-pro/kafka-events.md
165165
- Postgres events: ./openfaas-pro/postgres-events.md
166166
- AWS SQS events: ./openfaas-pro/sqs-events.md

0 commit comments

Comments
 (0)