It's not a secret anymore!*
The moose likes Threads and Synchronization and the fly likes MaximumThroughput- MltiThreading - Need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "MaximumThroughput- MltiThreading - Need help" Watch "MaximumThroughput- MltiThreading - Need help" New topic
Author

MaximumThroughput- MltiThreading - Need help

Anantha Reddy
Greenhorn

Joined: Jun 24, 2008
Posts: 12
Hi,

My requirement is to improve the batch execution speed by using maximum resouces of system.

Present batch execution.
1. We read no of records from DB in a java a program which needs to be tranfered to third party system.
2. For every 350 (put it in to Vector) records we start new Thread which in turn communicate with third party front end system(legasy) and process 350 records 1 by one,which inturn process and update its DB.
3. here we are invoking a Thread for every 350 records,here the problem is system proceesed 6000 records in 135 min and other day it took same time 135 min to process 12000 records.

here the diff is no of threds invoked to process records, say 6000/350=17 threads , 12000/350=34, batch is getting struck when it reaches140+ Threads, hence we have monitored and can conclude that our Env supports onlly 130 Concurrent threads.

Now i would like to pass the denominator (350) dynamically based on no of records to be processed.
ex: if there are only 350 records to process todays batch i will invoke maximum threads 130 and shre the the records on equal ratio to process, hence i will get maximum throughput.

Here challenge is I should make sure there should always 130 threads running in my env when batch starts, when ever some threads complete its work goes dead stage, i have to find how many threads are alive (Thread.activeCount()) after every some time intervel (Here I would like to use timer) , and invoke those no of threads agin (130-livecont) till the end of the batch.

I woul like to parameterise no of threads to be invoked and Time intervel to check for live thread ount.

can any one shed the light on above implementaion.

my requirement is:
1. needs to find out live count of threads after every 1 min (say), how to use timer or some thing else can be done?
2. Thread.liveCount() is enough to track live threds or any other work around?
3.how do i utilize timer in this scenario?
4. is it cause any memory issues like Gorbase Collection etc...


Here I am providing code sample that i am using presently.



if you need some clarifs someware on this topic pls mention.

Thanks in Antisipation...
Ananth
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

If i see a system that creates 130 threads to do some work i will make sure that it never gets into production.
Increasing the number of threads like that will not increase performance. Infact it will decrease it because of thread scheduling overheads. In this sort of a scenario your OS will only be busy swapping threads and before the thread can start work it will be swapped out to give the cpu to a different thread.

My suggestion is to use a threadpool. You have it readily available in jdk5 in the concurrent package. A backport of the same is also available for prior jdk 5. (just google for java backport concurrent)


apigee, a better way to API!
Paul Sisco
Greenhorn

Joined: Jun 15, 2008
Posts: 11
Originally posted by Nitesh Kant:
If i see a system that creates 130 threads to do some work i will make sure that it never gets into production.
Increasing the number of threads like that will not increase performance. Infact it will decrease it because of thread scheduling overheads. In this sort of a scenario your OS will only be busy swapping threads and before the thread can start work it will be swapped out to give the cpu to a different thread.

My suggestion is to use a threadpool. You have it readily available in jdk5 in the concurrent package. A backport of the same is also available for prior jdk 5. (just google for java backport concurrent)


I agree completely! You should do some tests with thread pools using different numbers of threads. You will see performance improve up to a point, then performance will degrade as you add more threads. The job being performed by each thread is a big factor, so the right number of threads for best performance can be different for different systems.

Another thing to consider is whether you want new threads for each execution, or if you want the threads started once and they will pull from work from a queue.

It will be a fun exercise, and you will learn quite a bit from it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42274
    
  64
Originally posted by Nitesh Kant:
If i see a system that creates 130 threads to do some work i will make sure that it never gets into production.

I'd be careful to make generalized statements like that. 130 threads is not an unreasonable number for a multi-core server.

Furthermore, we don't know what the threads are doing. There might be external circumstances that ensure that only a few of them are CPU-bound at any given time.


Ping & DNS - my free Android networking tools app
Anantha Reddy
Greenhorn

Joined: Jun 24, 2008
Posts: 12
Originally posted by Ulf Dittmer:

I'd be careful to make generalized statements like that. 130 threads is not an unreasonable number for a multi-core server.

Furthermore, we don't know what the threads are doing. There might be external circumstances that ensure that only a few of them are CPU-bound at any given time.


Hi,

my sysstem configuration is 4GB RAM, dual core processer where this batch invoked, and creeseponding DB server config is 32GB RAM and 8 Dual core Processor.

Each Thread responsibility is looking up third patry sys URL(Developed on mainframes)once and execute its process with some input data, each thread will process 500 records one by one, Third party sys supports 200 concurrent users (in layman terminalogy we can say each thred = 1 user (online user))

presently it is proceesing 200 records P/M when thread count reaches to 140 and getting struck, hence we would like to get rid on no of threads invoked and optimal use of threads to complete the batch AEAP.

in above scenario it is processing 12000 records p/h. on peack load batch may have to process 120000 records, when no of records ranges from 10000 to 40000 no of threads invoked is comparitively less, hence no of records processed P/M is less, which inturn causing the delay in completion of batch

if i reduce the denominator 350 to some low no, as there is no control over no of threads Invoked, if there is huge no of records to be processed(say 60000+ records) system will hang.

if any one can suggest some other approch or how do i effectively implementnt earlier i have given approach will be highly appreciated..

Thanks for your efforts...expecting good solution if some one come accross such kind of implementation

[ June 28, 2008: Message edited by: Anantha Reddy ]

[ June 28, 2008: Message edited by: Anantha Reddy ]
[ June 29, 2008: Message edited by: Anantha Reddy ]
Anantha Reddy
Greenhorn

Joined: Jun 24, 2008
Posts: 12
Originally posted by Paul Sisco:


I agree completely! You should do some tests with thread pools using different numbers of threads. You will see performance improve up to a point, then performance will degrade as you add more threads. The job being performed by each thread is a big factor, so the right number of threads for best performance can be different for different systems.

Another thing to consider is whether you want new threads for each execution, or if you want the threads started once and they will pull from work from a queue.

It will be a fun exercise, and you will learn quite a bit from it.


Hi Paul and ULF,

Thanks for informative replys,

Paul: i would like to calrify your Query.. Each thread job is to process the the given no of records and die, my requirement is to invoke new threads up to maximum with some no of records to each thread to processes.

We have to tranfer this data from 1 DB to another DB by using Third Party System(Mainframe sys), can pls you detail(shed lite)on how this type of scenario can be implemented with Queue.

We are using IBM JDK1.4.2.
Server Config: Windows Server 2003, no of processors 2, 3.20 Ghz, RAM 4 GB.

We have analysed the laste 15 days data and found that our environment supports maximum 130 threads to process maximum no of or records per minute.

According to above inputs if you detail further that would be great help.

Thank You.
[ June 29, 2008: Message edited by: Anantha Reddy ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MaximumThroughput- MltiThreading - Need help