Java Concurrent Programming
Hello Members,
I am kind of new to java programming (started working in java last 3-4 months)... I am working on an applicaiton which handles lot of transactions on a daily basis...I tried useing threadpool for handling concurrent requests by using the Linked Blocking Queue. The thread pool always will have 50-100 threads running in the background and these will share the work. What happens here is that I am not seering the real concurrency here due to some reasons...Each thread will pick the message from this LBQueue and open a seperate commandline process to run some command and give the output back as std out or as a file which will then be put into the queue. Servlet then will pick the response from the queue and returns to the caller. Right now, I am getting the only 2-3 transactions per second but I want to achieve atleast 10-15 TPS rate..I tried to increase the thread pool size from 25 to 50, 100, 200 but not seeing any CPU hike rather than its taking longer processing time. Can anybody help me how I can achive better TPS with concurrent programming in java...
Any help would be greately appreciated.. Thanks in advance....
Sudhakar
Re: Java Concurrent Programming
Processors can only process information at a certain max rate, no matter how many threads you spawn the processor will max out at some point. Within reason increasing the number of threads helps deal with several tasks at once, but increasing too much and you will start developing overhead from having to manage all those threads - probably the reason you see a longer processing time with increased threads. Optimize your code whichever way you can so each thread needs less processor time, and stick with fewer rather than more threads.
Re: Java Concurrent Programming
A good rule of thumb is try to stick to the same number of threads as you have processor cores, give or take one or two for user interactions/GUI if any.
Re: Java Concurrent Programming
A good thing to do as well is to go over the code that is run on each thread execution, try to cut down on unnecessary calls to new etc. Optimise the code so it will run faster.
// Json
Re: Java Concurrent Programming
Thanks a lot everybody for your responses... I did try some code optimizations and will take a look at one more time...Meanwhile, do you suggest a number for the thread pool size that I can limit ...
Thanks..
Sudhakar
Re: Java Concurrent Programming
Is integrating the commandline process into the main Java application an option? I think that's where you bottle neck lies.
Creating new processes is an expensive task when it comes to OS resources. If you managed to integrate all the processes into one you will certainly see a dramatic improvement in the TPS rate.
Re: Java Concurrent Programming
Quote:
Originally Posted by
vzwsudha
I did try some code optimizations and will take a look at one more time...
Are you using a profiler to find the bottlenecks? There's usually little benefit from trying to optimize code unless you know exactly what is slowing things down.
If you use a performance profiler to find the methods at fault, you can target your optimization effort.