5 Replies Latest reply on May 18, 2006 11:22 AM by vignesh76

    Server Info listThreadCpuUtilization();

    vignesh76

      I'm using ServerInfo listThreadCpuUtilization() (the "Total" value) to calculate the %CPU utilization of the Jboss server. I'm also taking in to account the no of CPUs while calculating this value. The problem is, I'm getting absurd values for CPU usage like 170% etc.

      The formula I'm using is:

      (Total CPU usage of all threads in millisecs in elapsed time interval / (elapsed time interval in milliseconds * no of cpus)) * 100

      Is the "Total" thread cpu utilization value from SeverInfo accurate enough to calculate %CPU utilization of the Jboss process?

      Environment:
      -------------------

      OS verison: fedora core (2.6.11-1.1369_FC4smp #1 SMP Thu Jun 2 23:08:39 EDT 2005 i686 i686 i386 GNU/Linux)

      Jboss Version: 4.0.3SP1

      I also read some Jira comment that --> "I don't think this (ServerInfo) MBean is working correctly on Linux 2.6 kernels with the NPTL." . Could the inaccuracy be because of the 2.6 kernel that i'm using?

      I'm trying to get this tested out on Solaris.

        • 1. Re: Server Info listThreadCpuUtilization();
          dimitris

          The total is just the sum of what gets reported by http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/ThreadMXBean.html#getThreadCpuTime(long) for each running thread, so the accuracy depends on the jdk implementation.

          Do you count the elapsed time interval between 2 calls? I don't know also if xCPU is a correct assumption.

          My take is the value of this information is to help you see how jboss spends internally its time, i.e. which threads are doing most of the work.

          If you want information on jboss as a process, you better take this from the operating system.

          • 2. Re: Server Info listThreadCpuUtilization();
            vignesh76

            Thanks for the reply.

            Yeah, I count the elapsed time interval between the 2 calls and the total cpu usage in this time interval. The no of CPUs is as reported by the jboss web-console, home page (Hardware section)

            The JVM i'm using is

            java version "1.5.0_05"
            Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
            Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)

            For example for a particular 2 minute interval the values I get are as follows

            total thread cpu usage in 2 mins -->298760 ms, elapsed cpu time-->120,000 * 2 (no of cpus) = 240000 ms that results in

            (298760 / 240000 ) * 100 = 124%

            I thought of making this monitoring OS independent, and so looked for a method to get the cpu usage from the JVM. I guess there's no other way to acquire the cpu usage from the JVM directly.

            • 3. Re: Server Info listThreadCpuUtilization();
              vignesh76

              I found another way to accurately calculate % CPU usage using J2SE 5.0 management MBean OperatingSystemMXBean, which has an attribute ProcessCpuTime. Using this value provided accurate results for % cpu usage. The JConsole monitoring application that comes with J2SE 5.0 also uses this MBean to report cpu usage.

              • 4. Re: Server Info listThreadCpuUtilization();
                dimitris

                Looking at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/OperatingSystemMXBean.html

                you'll see there is no ProcessCpuTime, so this is a Sun JDK feature (maybe is supported by other jdks as well).

                • 5. Re: Server Info listThreadCpuUtilization();
                  vignesh76

                  I thought it'll be useful to post a small code snippet also:

                  MBeanServerConnection server = ManagementFactory.getPlatformMBeanServer();
                  
                  OperatingSystemMXBean sunOperatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(server,
                   ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, com.sun.management.OperatingSystemMXBean.class);
                  
                  //cpu usage in milli secs
                  long currentCpuUsage = sunOperatingSystemMXBean.getProcessCpuTime()/1000000;


                  I could not find com.sun.management.OperatingSystemMXBean anywhere in jdk 5.0 docs. I came to know about it referring to the sourcecode of JConsole.

                  Regards