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/openfaas-pro/jetstream.md
+44-13Lines changed: 44 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,23 @@
1
-
# JetStream for OpenFaaS
1
+
# Queue Worker
2
2
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.
4
4
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).
6
6
7
+
> Note: This feature is included for [OpenFaaS Standard & For Enterprises](https://openfaas.com/pricing/) customers.
7
8
8
9
## Async use cases
9
10
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:
11
14
12
15
- Batch processing and machine learning
13
16
- Resilient data pipelines
14
17
- Receiving webhooks
15
18
- Long running jobs
16
19
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:
18
21
19
22
-[Exploring the Fan out and Fan in pattern with OpenFaaS](https://www.openfaas.com/blog/fan-out-and-back-in-using-functions/)
20
23
-[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
23
26
24
27
## Terminology
25
28
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
27
31
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.
32
36
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)
34
38
35
39
## Installation
36
40
@@ -44,9 +48,13 @@ nats:
44
48
streamReplication: 1
45
49
```
46
50
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.
48
56
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.
50
58
51
59
```yaml
52
60
queueMode: jetstream
@@ -58,8 +66,31 @@ nats:
58
66
port: "4222"
59
67
```
60
68
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
+
61
71
## Features
62
72
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
+
63
94
### Metrics and monitoring
64
95
65
96
Get insight into the behaviour of your queues with built in metrics.
0 commit comments