7 Replies Latest reply on Aug 21, 2008 1:13 PM by peterj

    servlet: how to spawn all processors

      Hi,

      I have an complex web app talking to other apps in other machines; running this web app in 2 cpus linux, every thing is normal, but running in 16 cpus with 8g system, it responds very slowly and only 1-2 cpus is busy (over 50% usages).

      The controller servlet is like regular one, multi-threaded. I'm wondering if there is any thing I can do to have all cpus work for these threads created by the servlet.

      Thanks lost in advance

      --
      John
      Toronto

        • 1. Re: servlet: how to spawn all processors
          peterj

          Running your web app across 16 CPUs is not a good idea. Due to CPU cache issues, contention among threads, and various other issues it is usually better to run such apps while affinitized to 2, 3 or 4 CPUs (depening on your app). At least that is what we have found in our testing.

          In Linux, you can use the taskset utility to set affinity. I suggest adding this to the script that starts jbossas.

          • 2. Re: servlet: how to spawn all processors

             

            "PeterJ" wrote:
            Running your web app across 16 CPUs is not a good idea. Due to CPU cache issues, contention among threads, and various other issues it is usually better to run such apps while affinitized to 2, 3 or 4 CPUs (depening on your app). At least that is what we have found in our testing.

            In Linux, you can use the taskset utility to set affinity. I suggest adding this to the script that starts jbossas.


            Thanks lots for the info, Peter.

            I did try the affinity setting (to 4 cpus for the app), but only 1-2 cpu busy. I guessed b/c all threads running in the same process from the main servlet.

            As the app is big one, and it's required to put it in 16-32 cpus machine. I'm still thinking how to make use of 4/8 cpus.

            --
            John

            • 3. Re: servlet: how to spawn all processors
              peterj

              The best way to run on more that 4 CPUs is to run multiple instances of the app server, affinitizing each to its own set of CPUs.

              See my LinuxWorld presentation at http://www.linuxworld.com/events/2007/slideshows/A2-johnson.pdf. It is somewhat dated, but does cover affinity management.

              • 4. Re: servlet: how to spawn all processors
                kjkoster

                 

                "john_woo@canada.com" wrote:
                I did try the affinity setting (to 4 cpus for the app), but only 1-2 cpu busy. I guessed b/c all threads running in the same process from the main servlet.


                There is a fair chance that your application is not as thread-able as you think it is. Do you do any manual synchronisation, or do you make heavy use of libraries that do internal synchronisation?

                Use JConsole to check that you are not exhausting the Tomcat connector thread pools (or other pools)

                Also, check that you are running with the server VM http://www.java-monitor.com/forum/showthread.php?t=18.

                • 5. Re: servlet: how to spawn all processors

                   

                  "kjkoster" wrote:
                  "john_woo@canada.com" wrote:
                  I did try the affinity setting (to 4 cpus for the app), but only 1-2 cpu busy. I guessed b/c all threads running in the same process from the main servlet.


                  There is a fair chance that your application is not as thread-able as you think it is. Do you do any manual synchronisation, or do you make heavy use of libraries that do internal synchronisation?

                  Use JConsole to check that you are not exhausting the Tomcat connector thread pools (or other pools)

                  Also, check that you are running with the server VM http://www.java-monitor.com/forum/showthread.php?t=18.


                  Thanks lots for the info, kjkoster.

                  However, the -server or GC option didn't help. As metioned, running in multi-cores is very slow. and 1-2 cpus keep busy, which is not happened in 1-2 cores machine. The only thing I can think of is the JVM, RTSJ. or even 32/64 bits issue.

                  --
                  John



                  • 6. Re: servlet: how to spawn all processors
                    kjkoster

                    Which leaves the question: are you sure that your application is written such that it does not serialize requests internally? If you have synchronisation bottlenecks you can start as many threads as you like, but only a few may actually be runnable.

                    You can check samples of the state of your threads using jconsole. If you find that most of them are waiting, blocked on a lock of some kinds it makes no difference how many processors you have.

                    So, what makes you so sure that all threads in your application are free to run?

                    • 7. Re: servlet: how to spawn all processors
                      peterj

                      I just now tried this on my Linux desktop at home and I saw all 4 CPUs in use.

                      What Linux distro are you running?

                      How are you verifying that only 2CPUs are in use?

                      With JBossAS running, get the PID for it (you can find it via "ps -ef | grep java") and post the result from running this command (replacing 9999 with the PID for JBossAS):

                      taskset -p 9999

                      If taskset indicates that the java process is affinitized to more than 2 CPUs, then kjkoster is correct in asserting that there is something about your app that is prevent proper parallelization.