Skip to content

Scale workers ​

Throughput is the number of tasks your workers run at once, divided by how long a task takes. There are three ways to raise the first number, and three controls on the server that cap it on purpose.

A task's life ​

Drawing the diagram…

Every task a worker holds is a lease of 30 seconds that the worker keeps renewing. A worker that dies stops renewing, and its tasks go back to waiting. For a job, Failed is the dead letter queue; for a workflow step, the engine decides.

Raise it ​

StepWhat changesWhen
1. Raise concurrencyTasks one worker process runs at onceThe process has CPU and memory to spare, and tasks mostly wait on I/O
2. Run more worker processesProcesses polling the same queuesOne process is out of CPU, or you want it to survive a crash
3. Run more server instancesCapacity of the SDK gatewayThe server is out of CPU and Redis is not: see Scale the server

Take them in that order. Any number of workers may serve the same queue; the server hands each task to one of them.

SettingDefaultWhat it does
concurrency4Tasks the process runs at once
prefetchhalf of concurrency, at least 1Extra tasks it holds ready, so a free slot never waits for a poll
lease_ttl_ms30,000How long a task stays claimed without a renewal. The worker renews every third of it
drain_timeout30 secondsHow long a stopping worker may finish what it holds
  • A worker holds up to concurrency + prefetch tasks. On a queue that must be shared fairly between few workers, keep prefetch low: prefetched tasks wait in one worker while another may be idle.
  • Each language uses what it has: threads in Python, Ruby, Rust and Java, goroutines in Go, tasks in .NET, processes in Elixir, async loops in TypeScript. PHP forks concurrency processes with ext-pcntl, and runs one task at a time without it.
  • A worker blocked for longer than the lease loses its tasks (LeaseExpired). For CPU-heavy handlers in a language with one interpreter thread, prefer more processes with a lower concurrency.

Queue workers and workflow workers scale differently ​

Queue workerWorkflow worker
Add workers whenjoobqui_queue_size of its queues growsRuns stay at a step for longer than the step takes, or steps time out waiting for a worker (schedule_to_start_ms)
One unit of workA whole jobOne step. A run of ten steps is ten tasks, possibly on ten different workers
What limits a single runThe job's handlerThe slowest step, and how long each step waits for a free slot
prefetchHelps short jobsKeep it low for long steps: a prefetched step waits in one worker while another may be idle

Steps of one run that are declared parallel run at the same time only if enough slots are free on the task queue, so size a workflow worker for the widest parallel group you expect, times the runs in flight.

A worker that does both shares one concurrency between jobs and steps. Split them into two deployments when one kind starves the other: see Queue workers and workflow workers.

Cap it ​

These are set on the server and apply to every worker, whatever its language: see Queue throttling and controls.

ControlEffectWhere
PauseWorkers stop taking the queue's jobs until it is resumedQueues page
ConcurrencyAt most that many of the queue's tasks run at once, across all workersQueues page
ThrottleAt most limit jobs per period, across all workers; a throttled queue hands out one task per pollQueues page
The console's Queues page: one card per queue with its waiting, running and dead counts, a concurrency slider, and Pause and Clear buttons.The console's Queues page: one card per queue with its waiting, running and dead counts, a concurrency slider, and Pause and Clear buttons.
The Queues page: pause, concurrency and throttle per queue (mock data).

A throttled or paused queue looks like slow workers. Check the Queues page before adding more.

What to expect ​

Measured with handlers that do nothing, on one shared 4-core machine, one worker process ran 1,900 to 2,700 jobs per second. Real handlers set the rate long before the worker or the gateway does. See Benchmarks for the tables and Capacity.

Check it worked ​

  • The Workers page shows every process, and how many of its slots are busy.
  • joobqui_queue_size{queue} falls, and joobqui_jobs_processed_total{queue} rises faster than before.
  • joobqui_queue_dead{queue} does not rise: more load often finds the errors a quiet system hid.