Skip to content

Commit 436e299

Browse files
authored
Add a few example techniques you can use with Worker (#492)
2 parents 7aa1298 + eb53299 commit 436e299

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

website/docs/techniques.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: Techniques
3+
---
4+
5+
This page outlines some of the techniques that may not be obvious but allow you
6+
to extract more power from Graphile Worker.
7+
8+
## Limiting concurrency
9+
10+
Out of the box, Graphile Worker supports jobs being added to a named queue (in
11+
which case that queue has a concurrency of 1) or not being added to a queue (in
12+
which case the jobs can execute as quickly as there are workers to execute
13+
them). Sometimes you want to limit concurrency to a small number, but larger
14+
than 1... Here are some techniques you can use to do this.
15+
16+
### Dedicated worker with specific concurrency
17+
18+
With this technique, you'd make sure that only one worker supports this task
19+
identifier (and that worker supports this task identifier only), and then you
20+
run this worker with the desired concurrency and make sure not to add the jobs
21+
to a named queue.
22+
23+
This is effective, but it requires running a separate worker which may spend a
24+
lot of time idle.
25+
26+
A variant of this technique is to run N dedicated workers each with concurrency
27+
M, where N\*M is your desired concurrency.
28+
29+
### Multiple queue names
30+
31+
Whether via round-robin, random, or some other method; this technique has you
32+
create as many named queues as you need concurrency and schedule tasks into
33+
these queues.
34+
35+
One trade-off of this approach is that jobs may not be ran in the desired
36+
order - order is only maintained within each named queue, but if jobs in one
37+
named queue execute faster or slower than others, the tasks may come out of
38+
sync.
39+
40+
### Forbidden flags
41+
42+
[Read more here](/docs/forbidden-flags).
43+
44+
## Managing priority
45+
46+
So you've got some new jobs that need to execute _right now_, but your workers
47+
are all busy executing long-running boring background tasks already? Here's some
48+
solutions!
49+
50+
### Dedicated high-priority worker
51+
52+
Assuming that your high priority tasks belong to their own task identifier, you
53+
can run a separate worker that's dedicated to this task identifier and will pick
54+
up on the jobs as soon as they're available (assuming you have sufficient
55+
concurrency).
56+
57+
### Run greater concurrency
58+
59+
Either running more workers or have your workers have higher concurrency, or
60+
both.
61+
62+
### Limit concurrency of slow tasks
63+
64+
Use the "limiting concurrency" techniques above on your slow tasks, which should
65+
mean that you always have reserve capacity available for high priority jobs.
66+
67+
## Scale up on-demand
68+
69+
### Worker events
70+
71+
Use [the events system](/docs/worker-events) to detect when your workers are
72+
overwhelmed, and scale up as necessary. One common signal for this is when the
73+
`run_at` of a job that you start executing is significantly before the current
74+
time minus the `pollInterval` (assuming that your database and worker clocks are
75+
synchronized).

0 commit comments

Comments
 (0)