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
Check these values
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.
Your result
How it was worked out
How to use this calculator
- Choose a rule. Threads from cores and wait time is the first choice.
- 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.
- Or choose Little's law: type the tasks at your busiest time and the time each task holds a thread.
- 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
- For connections open at the same time from a rate and a duration, use the Concurrent Connection Calculator.
- To see which of your limits fills first, use the Connection Saturation Calculator.
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.