Skip to content

Worker pool

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

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

  • In a sibling library: Go: A worker pool ↗
  • In the books: Effective Concurrency in Go, Burak Serdar — ch. 5, 'Worker Pools and Pipelines'
  • In the books: Async Rust, Maxwell Flitton, Caroline Morton — ch. 3, 'Building Our Own Async Queues' → 'Increasing Workers and Queues'
  • In the books: Programming with POSIX Threads, David R. Butenhof — ch. 4, 'A Few Ways to Use Threads' → 'Work crew'
  • In the books: The Little Elixir & OTP Guidebook, Benjamin Tan Wei Hao — ch. 6, 'Fault tolerance with Supervisors' → 'Implementing Pooly: a worker-pool application'
  • In the books: asyncio Recipes, Mohamed Mustapha Tahrioui — ch. 5, 'Working with Async Context Manager' → 'Writing a Loop Worker Pool Async Context Manager'
  • In the books: JavaScript Concurrency, Adam Boduch — ch. 7, 'Abstracting Concurrency' → 'Worker pools'