Toolvito

Works on this device

Thread Pool Size Calculator

Estimate how many threads a worker pool needs. Use the rule with CPU cores and the wait and compute time of one task, or Little's law with a task rate and the time each task holds a thread. Each result is an estimate with its assumptions; measure before you rely on it.

Enter your values

A pool for tasks that use the CPU part of the time and wait the rest: threads = cores × target CPU use × (1 + wait time ÷ compute time).

Your values

The cores the program can use. A core with two hardware threads may count as two; check how your system counts.

The share of the cores you want this pool to keep busy. Lower it when other work shares the machine.

Time a task waits without using a core: for a database, a disk, a network call or a lock. From your own measurements.

Time a task uses a core.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Calculate.

How to use this calculator

  1. Choose a rule. Threads from cores and wait time is the first choice.
  2. Type the CPU cores, the share of them you want the pool to use, and the wait time and compute time of one task from your own measurements.
  3. Or choose Little's law: type the tasks at your busiest time and the time each task holds a thread.
  4. Choose Calculate. The result is rounded up to a whole thread.

The two rules

  • Cores and wait time: threads = cores × target CPU use × (1 + wait time ÷ compute time). A task that waits 9 times as long as it computes needs about 10 threads for each core. From *Java Concurrency in Practice* (Brian Goetz and others, 2006).
  • Work that only computes: about one thread for each core, often cores + 1.
  • Little's law: threads busy on average = tasks each second × time each task holds a thread. Add room to spare for bursts.
  • Most tasks a pool can finish = threads ÷ time per task. Use of a pool = tasks each second × time per task ÷ threads.

Worked examples

Cores and wait time: 8 cores at 100%, tasks that wait 90 ms and compute 10 ms: 8 × 1 × (1 + 90 ÷ 10) = 80 threads. The cores then allow at most 8 ÷ 0.01 = 800 tasks each second, which is the same as 80 threads ÷ 0.1 s.

Little's law: 400 tasks each second that each hold a thread for 100 ms keep 400 × 0.1 = 40 threads busy. With 20% to spare that is 48 threads.

A pool you have: 50 threads and 100 ms per task finish at most 500 tasks each second. At 400 each second the pool is 80% busy.

Other tools for the same subject

Limits you should know

  • Both rules are estimates. They assume tasks of the same length that do not slow each other down.
  • A database, a disk or a service that the tasks call has its own limit. More threads then only add waiting there, and use more memory.
  • The tool runs no program and measures nothing. Test the size under real load.

Related tools