This content has been marked as final. Show 2 replies
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.
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.