Skip to content

Worker pool

Category: Communication · Status: stub · Lessons: chapter 05, Message passing

One line: A fixed number of workers take jobs from one shared queue, which bounds how much work runs at once.

Also called: thread pool.

How it connects

flowchart LR
  n_channel["Channel"]
  n_worker_pool["Worker pool"]
  n_worker_pool -->|uses| n_channel
  classDef center stroke-width:3px
  class n_worker_pool center
  classDef outside stroke-dasharray: 4 3
  class n_channel outside

In each language

Rust no pool in std; the Rust Book builds a ThreadPool ↗ whose workers share one receiver behind Arc<Mutex<T>>
Go no pool type: a fixed number of goroutines ranging over one jobs channel, the bounded parallelism of the Go blog's pipelines post ↗
Java Executors.newFixedThreadPool ↗: a fixed number of threads operating off a shared unbounded queue
Python ThreadPoolExecutor ↗
C# the process-wide ThreadPool ↗, which executes tasks, work items and asynchronous I/O
JavaScript Node's Worker Pool ↗ handles expensive tasks such as file I/O away from the event loop
Erlang and Elixir Task.async_stream ↗ with max_concurrency

Where to read more