• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Multithreaded application performance sucks, pl help

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
R Jelda
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
R Jelda
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic