2 Replies Latest reply: Aug 20, 2011 6:39 AM by matfud RSS

    Number of threads, CPU Usage and JMeter

    723953
      I am struggling with a tester application which starts configured number of thread. I am facing problems with the CPU usage. To overcome this I have written a test application which starts up 'x' number of threads. Each thread simply prints out the a system out to the console. nothing else. With 20 threads, the CPU usage rises to 40-50%.

      A similar comparision is a JMeter Web test. I have test script which just access www.yahoo.com site and is done. With 20 users which is 20 thread the CPU Usage is just half to my simple tester.

      Suggest any tips to reduce the CPU usage. JMeter code is too vast to come to a solution in short period of time. Please suggest.
        • 1. Re: Number of threads, CPU Usage and JMeter
          796440
          My guess is that since JMeter is hitting a website--and one with non-trivial content at that--it's spending a lot more time on I/O than your code, so the CPUs spend a lot more time waiting.

          If you think the CPU usage of your simple test program is too high, then one of two things is happening: 1) You're doing something really dumb in your code. Nobody here can help you with that without seeing the code. 2) Your mistaken in your assumption about how much CPU it "should" use.

          And of course, the amount of CPU used by such a simple program is absolutely, totally, completely, 100% meaningless anyway. It won't tell you anything about how to use multithreading in real programs.
          • 2. Re: Number of threads, CPU Usage and JMeter
            matfud
            While waiting for IO your code should have almost zero overhead (i.e. I will not be using up much CPU time). As you start receiving data on each thread then the CPU usage will rise. How far it rises will depend on how your code reads that data (byte at a time is slow) and what your code does with the information when it has it (HTML tidy, HTML processing, XML processing, validation etc). Many tasks can be quite expensive.

            So just comment out the rest and see what happens when you're code only does IO. Just get the threads to request the data and see how it impacts the CPU usage you are seeing. And do not attach a debugger and ensure your machine is not hitting swap space.

            If that is all fine then you need to look at how you are processing the information.

            Without any code we can not help you.

            matfud