views:

293

answers:

4

Hi all
I'm writing a java application that runs in Tomcat, on a multi-core hardware. The application executes an algorithm and returns the answer to the user. The problem is that even when I run two requests simultaneously, the tomcat process uses at most one CPU core.
As far as I understand each request in Tomcat is executed in separate thread, and JVM should run each thread on separate CPU core.

What could be the problem that bounds the JVM or Tomcat to use no more than one core?

Thanks in advance.

+1  A: 

All the processor management will be taken care by the server itself. It is not mandatory that if you pass two requests, it should use two CPUs.

RaviG
So how can I manage it to run different CPUs?
jutky
Resource allocation is not in our hands. But the server administrator can configure the load balancing between two servers depending on some conditions like the memory utilization, CPU utilization etc.,
RaviG
I'm running the tomcat by my own, so it should be in my hands.
jutky
A: 

Are you sure that two threads are being created. You could simply print the name of the thread as a quick test.

What happens if you run the algorithm in a standalone app?

Karl
After a lot of tests I've found that in the standalone app the same problem still exists. I continued with detailed profiling and made a decision that when FULL GC is running all other threads are sleeping and I see that only one CPU core is in use. The problem is that the algorithm is memory greedy and almost all the time JVM tries to run FULL GC. So there is no problem in Tomcat, I will now review the memory usage, and try to find where I can save memory wastes. I mark this answer as correct because it lead me to the correct conclusion (despite the fact it is not really solving the problem).
jutky
A: 

Are you executing any synchronized blocks/methods which would force serial execution? The tomcat connector configuration in server.xml controls the request thread pool - but the default is 200 threads, IIRC.

rwhit
I do have synchronized blocks, but as far I've checked they don't cause the problem. I try to recheck it once again.
jutky
A: 

Here is the procedure to do a load balancing in tomcat http://tomcat.apache.org/tomcat-5.5-doc/balancer-howto.html

I think this will work with Tomcat 6 too as they mentioned balancer webapp is shipped with tomcat 5.0 and later.

RaviG