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/develop/task-queue-priority-fairness.mdx
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ tags:
17
17
18
18
importSdkTabsfrom'@site/src/components';
19
19
20
-
[Task Queue Priority](#task-queue-priority) and [Task Queue Fairness](#task-queue-fairness) are two ways to manage the distribution of work within Task Queues. Priority focuses on how Tasks are prioritized within a Task Queue and Fairness aims to prevent one set of prioritized Tasks from blocking others within a single Task Queue.
20
+
[Task Queue Priority](#task-queue-priority) and [Task Queue Fairness](#task-queue-fairness) are two ways to manage the distribution of work within Task Queues. Priority focuses on how Tasks are prioritized within a Task Queue and Fairness aims to prevent one set of prioritized Tasks from blocking others within the same Task Queue.
21
21
22
22
:::tip Support, stability, and dependency info
23
23
Priority and Fairness is currently in [pre-release](/evaluate/development-production-features/release-stages#pre-release).
@@ -26,21 +26,23 @@ Please contact your AE or Support to enable this feature.
26
26
27
27
## Task Queue priority
28
28
29
-
**Task Queue priority** lets you control the execution order of Workflows, Activities, and Child Workflows based on assigned priority values within a *single* Task Queue.
29
+
**Task Queue priority** lets you control the execution order of Workflows, Activities, and Child Workflows based on assigned priority values within a *single* Task Queue. Each priority level acts as a "virtual" task queue that prioritizes Tasks within a single Task Queue.
30
30
31
31
If you're using Temporal Cloud, contact Temporal Support or your Temporal account team to enable this feature for your cloud Namespaces.
32
32
33
33
If you're self-hosting Temporal, use the latest pre-release development server and set `matching.useNewMatcher` to `true` in the [dynamic config](https://github.com/temporalio/temporal/blob/a3a53266c002ae33b630a41977274f8b5b587031/common/dynamicconfig/constants.go#L1345-L1348) on the relevant Task Queues or Namespaces.
34
34
35
35
### When to use priority
36
36
37
-
If you need a way to specify the order your Tasks execute in, you can use priority to manage that. Priority gives you a way to differentiate between batch and real-time Tasks so that you can allocated resources more effectively. You can also use this as a way to run Tasks immediately and override others if you have an urgent Task.
37
+
If you need a way to specify the order your Tasks execute in, you can use priority to manage that. Priority gives you a way to differentiate between different Tasks you have, like batch and real-time, so that you can allocate resources more effectively. You can also use this as a way to run urgent Tasks immediately and override others.
38
38
39
39
### How to use priority
40
40
41
41
You can select a priority level by setting the _priority key_ to a value within the integer range `[1,5]`. A lower value implies higher priority, so `1` is the highest priority level. The default priority, if unspecified, is `3`.
42
42
43
-
When you set a priority level within your Task Queues, this means that they will __all__ be processed in priority order. Each priority level acts as a separate virtual task queue. For example, all your priority level `1` Tasks will execute before your priority level `2` Tasks and so on. So your lower priority Tasks will be completely blocked until the higher priority Tasks finish running. Tasks with the same priority are scheduled in first-in-first-out (FIFO) order. If you need more flexibility to allocate resources to lower priority Tasks sooner, check out [the fairness section](#task-queue-fairness).
43
+
When you set a priority level within your Task Queues, this means that they will __all__ be processed in priority order. For example, all your priority level `1` Tasks will execute before your priority level `2` Tasks and so on. So your lower priority Tasks will be completely blocked until the higher priority Tasks finish running. Tasks with the same priority level are scheduled to run in first-in-first-out (FIFO) order. If you need more flexibility to allocate resources to lower priority Tasks sooner, check out [the fairness section](#task-queue-fairness).
44
+
45
+
Activities will inherit the priority level of their Workflow if a separate Activity priority level isn't set.
@@ -199,17 +201,17 @@ Task Queue fairness applies within each priority level. This gives you more cont
199
201
- Multi-tenant applications with big and small tenants where small tenants shouldn't be blocked by big ones. That means any single user should be able to use all available resources rather than being rate limited at a fixed level.
200
202
- Assigning Tasks to different capacity bands and then dispatch 80% from one band and 20% from another, for example, without limiting overall capacity when one band is empty.
201
203
202
-
To enable this feature, use the latest pre-release development server and set `matching.enableFairness` to `true` in the [dynamic config](https://github.com/temporalio/temporal/blob/a3a53266c002ae33b630a41977274f8b5b587031/common/dynamicconfig/constants.go#L1350-L1353) on the relevant Task Queues or Namespaces.
204
+
Fairness is only avaliable in Temporal Cloud, so contact Temporal Support or your Temporal account team to enable this feature for your cloud Namespaces.
203
205
204
206
:::warning
205
207
For **Pre-release**, fairness cannot be enabled for active Task Queues. The Task Queues have to be new or idle and there can't be any running Workflows. Once fairness is enabled, all existing backlog Tasks in the Task Queue will be abandoned.
206
208
:::
207
209
208
210
### How fairness works
209
211
210
-
Fairness creates multiple “virtual queues”, one for each _fairness key_, within a Task Queue. The fairness keys are used to describe your Task structure. A fairness key can correspond to unique applications, tenants, or other groupings useful to your workloads. The Tasks associated with each fairness key are dispatched based on the _fairness weight_ that has been assigned to the key. Using the fairness keys and their corresponding fairness weights lets you define tiers with weighted capacities, like high, medium, and low, so that higher priority tasks don't overwhelm your resources and block lower priority tasks.
212
+
Fairness sequences Tasks at each priority level based on each _fairness key_ and their _fairness weight_ within a Task Queue. The fairness keys are used to describe your Task structure. A fairness key can correspond to unique applications, tenants, or other groupings useful to your workloads. The Tasks associated with each fairness key are dispatched based on the _fairness weight_ that has been assigned to the key. Using the fairness keys and their corresponding fairness weights lets you define tiers with weighted capacities, like high, medium, and low, so that higher priority tasks don't overwhelm your resources and block lower priority tasks.
211
213
212
-
Fairness attempts to distribute all the Tasks from a higher priority level first before distributing any from a lower priority. There are also _fairness weights_ which is the weight assigned to a fairness key to allow for unequal distribution among tenants or for allocating fractions of capacity to different levels or types of Tasks.
214
+
Fairness attempts to distribute all the Tasks from a higher priority level first before distributing any from a lower priority. The fairness weights allow for unequal distribution among tenants or for allocating fractions of capacity to different levels or types of Tasks.
213
215
214
216
Fairness applies within each priority level. It sequences Tasks in the Task Queue probabilistically using a weighted round-robin, based on:
215
217
@@ -219,15 +221,15 @@ Fairness applies within each priority level. It sequences Tasks in the Task Queu
219
221
220
222
### When to use fairness
221
223
222
-
Fairness applies to backlogged Tasks when there isn't sufficient Worker capacity to dispatch Tasks immediately. If all Tasks can be dispatched immediately, then you don't need to use fairness. Fairness is applicable if you want to distribute a finite resource across all of your Tasks without blockers.
224
+
Fairness applies to backlogged Tasks when there isn't sufficient Worker capacity to dispatch Tasks immediately. This is applicable if you want to distribute a finite resource across all of your Tasks without blockers. If all Tasks can be dispatched immediately, then you don't need to use fairness.
223
225
224
226
Fairness applies at Task dispatch time based on information about the Tasks passing through the Task Queue and considers each Task as having equal cost. It doesn't consider any Task execution that is currently being done by Workers. So if you look at Tasks being processed by Workers, you might not see "fairness" across tenants.
225
227
226
228
### Limitations of fairness
227
229
228
230
When you use Worker Versioning and you're moving Workflows from one version to another, the ordering of Workflow Tasks that are moved to the next version is undefined. Tasks redirected to a new Worker version may not be treated fairly with respect to each other or Tasks that aren't redirected.
229
231
230
-
There isn't a limit on the number of fairness keys you can use, but their accuracy can degrade as you add more fairness keys.
232
+
There isn't a limit on the number of fairness keys you can use, but their accuracy can degrade as you add more.
231
233
232
234
Task Queues are internally [partitioned](/task-queue#task-ordering) and Tasks are distributed to partitions randomly. This could interfer with fairnesss. Depending on your use case, you can reach out to Temporal Support to get your Task Queues set to a single partition.
0 commit comments