Skip to main content

Module work_queue

Module work_queue 

Source
Expand description

A self-balancing work queue.

A work queue distributes items from one or more producers across a fixed set of workers. Each worker has its own bounded queue, so workers never contend with each other on a shared receiver.

Items keep going to the same worker until it has a backlog of a few queued items. A moderately loaded queue therefore keeps as few workers busy as it can, which avoids waking up idle workers for every item. Once that worker falls behind, items go to whichever worker has the fewest queued items, so no worker sits idle while another has a backlog.

Each sender balances independently, based on how many items are currently queued for each worker. Items already queued for a worker stay with that worker, so a worker that stops making progress holds on to its backlog. Workers that have stopped, by dropping their receiver, are skipped, and items queued for them are dropped.

Structs§

SendError
An error returned when sending to a work queue whose workers have all stopped.
WorkQueueReceiver
The receiving side of a work queue, for a single worker.
WorkQueueSender
The sending side of a work queue.

Functions§

bounded
Creates a bounded work queue with workers workers.