Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasonable number of threads for thread pool running web service requests

When creating an FixedThreadPool Executor object in Java you need to pass an argument describing the number of threads that the Executor can execute concurrently. I'm building a service class that's responsibility is to process a large collections of phone numbers. For each phone number I need to execute web service (that's my bottleneck) and then save response in a hashmap.

To make this bottleneck less harmful to the performance of my service I've decided to create Worker class which fetches unprocessed elements and processes them. Worker class implements Runnable interface and I run Workers using Executor.

The number of Workers that can be run in the same time depends on the size of Executor FixedThreadPool. What is the safe size for a ThreadPool? What can happen when I create FixedTheradPool with some big number as an argument?

like image 341
mgamer Avatar asked Jun 22 '09 18:06

mgamer


People also ask

What is the ideal thread pool size?

So the ideal thread pool size is 4 cores * 2 * ( 1 + 9 ) = 80. If all 100ms are calculation, 0ms is waiting. the blocking coefficent is 0. The ideal thread pool size is 4 * 2 * 1 = 8.

How do I figure out how many threads I need?

By dividing the amount of thread by the seam length, we get the ratio of thread consumed. If we multiply this factor times the total length of seam, we can determine the total thread consumed for that seam.

Why a thread pool should not be too big or too small?

using a thread pool that is too large or too small – if the thread pool contains too many threads, this can significantly affect the performance of the application; on the other hand, a thread pool that is too small may not bring the performance gain that you would expect.


1 Answers

Something that could be considered is looking at

Runtime.getRuntime().availableProcessors()

which gives some direction on how many threads that would make sense for the system.

like image 60
Lars Andren Avatar answered Sep 19 '22 16:09

Lars Andren