FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Thread_pool_pattern

Thread pool

A sample thread pool (green boxes) with waiting tasks (blue) and completed tasks (yellow)

In computer programming, a thread pool is a software design pattern for achieving concurrency of execution in a computer program. Often also called a replicated workers or worker-crew model, a thread pool maintains multiple threads waiting for tasks to be allocated for concurrent execution by the supervising program. By maintaining a pool of threads, the model increases performance and avoids latency in execution due to frequent creation and destruction of threads for short-lived tasks. Another good property - the ability to limit system load, when we use fewer threads than available. The number of available threads is tuned to the computing resources available to the program, such as a parallel task queue after completion of execution.

The cost of having a larger thread pool is increased resource usage. The algorithm used to determine when to create or destroy threads affects the overall performance:

In languages

edit

In bash implemented by --max-procs / -P in xargs, for example:

$ timegorunworker-pools.go worker 1 started job 1 worker 2 started job 2 worker 3 started job 3 worker 1 finished job 1 worker 1 started job 4 worker 2 finished job 2 worker 2 started job 5 worker 3 finished job 3 worker 1 finished job 4 worker 2 finished job 5 real 0m2.358s

With unbuffered channels:

  • ↑ Garg, Rajat P. & Sharapov, Ilya Techniques for Optimizing Applications - High Performance Computing Prentice-Hall 2002, p. 394
  • ↑ Holub, Allen (2000). Taming Java Threads. Apress. p. 209.
  • ↑ "GitHub - vit-vit/CTPL: Modern and efficient C++ Thread Pool Library". GitHub. 2019-09-24.
  • ↑ "Controlling Parallelism (GNU Findutils 4.10.0)". www.gnu.org. Retrieved 2025-01-26.
  • ↑ "The Case For A Go Worker Pool — brandur.org". brandur.org. Retrieved 2021-07-27. Worker pools are a model in which a fixed number of m workers (implemented in Go with goroutines) work their way through n tasks in a work queue (implemented in Go with a channel). Work stays in a queue until a worker finishes up its current task and pulls a new one off.
  • External links

    edit
    Software design patterns
    Gang of Four
    patterns
    Creational
    Structural
    Behavioral
    Concurrency
    patterns
    Architectural
    patterns
    Other
    patterns
    Books
    People
    Communities
    See also

    View original on Wikipedia | Back | FazBrowse Home