aspose file tools*
The moose likes Performance and the fly likes Multithreaded application performance sucks, pl 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 » Performance
Bookmark "Multithreaded application performance sucks, pl help" Watch "Multithreaded application performance sucks, pl help" New topic
Author

Multithreaded application performance sucks, pl help

R Jelda
Greenhorn

Joined: May 13, 2002
Posts: 26
Hi,
I have got a severe problem with performance when I run a multithreaded application.
We use our own Java-Server.(Web applicaitons)
It does not has any synchronized methods or synchrnonization.But only some times it uses an "Unsynchronized vector/Hashtable" to read the data from it.
We have 2 steps of execution.
1)Reading phases -- reads the streams and instantiates the objects and saves it locally.
2)Executes those objects..(like strategy pattern)-For a while think it like this.
The problem is,
A single thread applicaiton takes suppose 500ms.
Where as 10 Multithreaded application is taking almost around 5000ms each.
Can anyone please point out,why this is happening.
Can anyone please put me on right track.
B.Regards,
Jelda


"If you have an apple and I have an apple and we exchange apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas." -George Bernard Shaw
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

5000 ms each, meaning 10x5000 = 50,000 ms or almost one minute for all ten? Or in 5 seconds, all ten complete, but each one takes basically the whole 5 seconds?


[Jess in Action][AskingGoodQuestions]
R Jelda
Greenhorn

Joined: May 13, 2002
Posts: 26
A single thread applicaiton takes suppose 500ms.
Where as 10 Multithreaded application is taking almost around 5000ms each.
i.e
in 5 seconds, all ten complete, but each one takes basically the whole 5 seconds. Actually each one doesn't take exactly 5 seconds. Some are taking 4sec,some 5 sec etc. But the thing here is all threads take much more unacceptable time when comapared to single threaded application (i.e 500Sec).
I couldn't understand why this is happening,which is really unacceptable.
Regards,
Jelda
[ January 13, 2004: Message edited by: R Jelda ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

On a single-processor machine, if you create ten threads, then each one only gets one-tenth of the processor and other machine resources. A 1/2 second process can thus take 5 seconds, even in the absence of explicit synchronization.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Now it's still possible that creating multiple threads will be able to speed up your performance, and you've got some (fixable) bug which is preventing this. EFH's point is that it can be entirely reasonable to see numbers like this. Most commonly, if the tasks performed by the threads are all very processor-intensive, then 10 threads won't perform any better than one. They're all competing for the same thing, namely processor time. Or maybe there's some other shared resource which they're all waiting for - depending what that is, it may be something that doesn't multi-thread well. But again, you may just have a bug somewhere. I'd suggest doing some profiling to see where the threads are spending their time. Use something like JProbe if you can afford it; otherwise try running the java -Xprof option. Find where your threads are spending most of their time, and ask yourself if it's reasonable to expect them to be able to work faster than they are. Good luck...


"I'm not back." - Bill Harding, Twister
R Jelda
Greenhorn

Joined: May 13, 2002
Posts: 26
HI,
Thanks for you replies.
Yeap,It looks like all the threads are sharing the a single processor and slowing down.
I am almost 200% sure that,there is really no bug in my Multithreaded program.And I found that the most time spent is on Vectors and Hashtables in reading values.
If the time taken is so long in this Multithread program,It is really unacceptable in our applicaiton.
I heared that by default,Java uses only Greenthreads from jdk1.3.And how could I make java use just only native threads instead green.(Ofcourse we use multiprocessors too at some clients.But suppose We use only a single processor)
Regards,
Jelda
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
You heard incorrectly - "Green" Threads only occur in certain JVMs. As I recall, early Solaris JVMs had to use Green threads for some reason. On Windows JVMs use native Threads - I have used multiple Threads to good effect on a dual processor NT system.
It is not clear from your description, but if you are reading multiple streams, you may get an improvement by putting reading and processing in a single Runnable object. Other threads can run while the system is doing IO for the streams. That is what I did, and observed good CPU utilization on both CPUs.
If you are using Vectors and Hashtables, you are taking a synchronization hit that may not be necessary. Only Vectors and Hashtables that may be read by more than one Thread need synchronization - thats why ArrayList and HashMap exist.
You should also check the effect of various memory allocations and the various JVM settings - see the tooldocs.
Bill
[ January 14, 2004: Message edited by: William Brogden ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multithreaded application performance sucks, pl help