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
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 ]
author and iconoclast
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.
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
Joined: May 13, 2002
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
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 ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Multithreaded application performance sucks, pl help