High, I am wondering if anyone could give me some input on a design question I am pondering. Right now I have a java program that spikes my CPU ussage to 85% every 1 second when it performs a lot of calculations on a stream of data. I want to take advantage of dual processors but don’t want to redesign the program to make it multithreaded as I’ve spent a lot of time debugging and testing what I have now. What if I run the program in two seperate JVM instances and split the workload would that in theory improve performance? – Duncan
Share
if you are going to split the workload, you would probably be better off refactoring what you have to be multithreaded…
futhermore, if you are worried about breaking something that is working, it means you didn’t write enough tests to ensure that future refactorings will go smoothly. So the recommendation would be to write some tests that capture your core functionality, then refactor to split you problem space up and make use of threading.
threading can speed up a program in many ways:
1) if you have multiple cores, a threading can be utilized to take advantage of those cores.
2) if you program is IO intensive, then it makes sense to split the computational parts off into threads separate from the threads that handle the IO. You will see this is cases where your program is running, but the cpu is not pegged, but your disk is.
3) other things people smarter than me know.
you can also go overboard in your threading — it might not make sense to spawn 1000 threads to run on one cpu. The overhead of maintaining the threads might drag down performance.
edit – the overhead for running 2 jvms is much higher than the overhead for running a few threads.
finally – if the problem is something like ‘do something with the text in a bunch of file’, then yes, you could just separate the files into 2 separate directories and point a different running instance of your program at each. however that feels dirty to me…