Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ThreadCount for best Throughput??  RSS feed

 
Joe Joseph
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Suppose i have a Solaris box with 2 CPU's and i use Threads (Java threads or Websphere AsyncBeans) to do some work in parallel. Is there any means to arrive at the ThreadCount that would give me the best throughput.
Other than the Number of CPU's and the OS versions, is there any other variable which would contribute to deciding this. I know that there is no one single magic number to decide the ThreadCount to use, but if there is some guideline then it would be helpful
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this: ThreadGroups Should have a ThreadCount or something.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True there is no magic number for the best throughput, however, the following is a piece of advice i can offer:
If you are consuming 100% of the CPU then that is the best you can do with the threadcount as such. Increasing the threads after 100% cpu usage will start degrading the throughput because of thread scheduling overheads.
So, you really need to do some load testing to see whether at high load your app is getting close to 100% cpu usage. If not you may try out increasing thread count. This is easier said than done and more so in an application deployed on an app server. The reason being that apart from your threads you may have a lot of other threads running that may not be in your control.

Ideally, if all the work your application do is truly parallel i.e. no shared data, no synchronization then 1 thread per core should work out best for an app but that is normally not the case and every app has some shared data that needs synchronization and hence the parallelism turns to sequential processing.
What I am trying to say in the above statements is that it is very difficult to offhand tell without profiling and load test that what will be the ideal thread count for best throughput. You need to analyze with load testing and profiling tools as to what is the level of parallelism in your application, Is there any spare computing resources you can use, etc.

Hope this helps.
I think this question is more appropriate for the performance forum.
[ April 23, 2008: Message edited by: Nitesh Kant ]
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, there is no magic here. It depends on many factors.

The number of cores is important. For example, it is silly to only have a threadpool of 30 threads when you have a machine with 384 cores on the box (the largest box that I used so far). The reverse may be also true.

The number of thread pools is also important. For example, if you are writing one small webservice in an application server that has many other services, with there own pools, there may be no reason to use all the cores with your pool (other pools can use them too).

What is being done is also important. If a thread is spending half it's time in IO waits, then maybe you can double the number of threads, as you don't actually need cores to wait for IO.

Henry
[ April 24, 2008: Message edited by: Henry Wong ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!