0
votes

I have few questions and I have searched for below questions over the net but got more confused.

  1. I have java application running on single machine with single JVM , 20 core machine with 20 GB ram with 20 java thread. ( single machine, single JVM, 20 core, 20 GB ram, 20 java threads )
  2. I have java application running on single machine with 20 JVM, 20 core mahcine with 1 GB ram to each JVM with 1 JAVA thread to each process. ( single machine, 20 JVM, 20 core, 20 GB ram, 20 java threads )

From above points 1 and 2 which one is better and why in terms of

  • Performance of application
  • CPU utilization of machine
  • If CPU is not consumed fully even increasing the number of threads, then what to do in application or machine in order to utilize more CPU.
  • In which case context switching will be more.

In above 1 and 2 point, lets say each thread takes 10ms to complete the task then, in how much time all the tasks will be completeed in case 1 and 2. Please explain.

I have search and heard about CPU intensive and I/O intensive application in regard of CPU utilization. Can you please explain a bit as over net I got confused alot.

Generally it is recommened to have number of threads equal to number of cores. If i have more number of thread then cores then what will be the impact. Please explain.

1

1 Answers

0
votes

You have a lot of different variables in play there and there isn't going to be a simple answer. I'll add some details below, but the tl;dr version is going to be "run some tests for your scenario and see what works the best".

Whether or not you should have one thread per cpu depends on your workload. As you've already apparently found, if your thread is cpu intensive (meaning, most of the time it is actively using the cpu), then one thread will come close to fully utilizing one cpu. In many real-world situations, though, it's likely that your thread may have to do other things (like wait for I/O), in which case it will not fully utilize a cpu (meaning you could run more than one thread per cpu).

also, in your two scenarios, you need to account for all the jvm overhead. Each jvm will have many of its own threads (most notably, the GC threads). These will add additional overhead to your cpu usage. If your code makes heavy use of the garbage collector (creating/discarding a large amount of garbage while working), it may be beneficial to have separate jvms per thread, but you'll need to account for the additional gc thread cpu usage. if your code does not make a lot of garbage, then using separate jvms (and many extra gc threads) may just be wasting resources.

Given all these variables, as well as the actual workload profile of your threads, you are unlikely to find the right answer with theory alone. Testing a variety of scenarios with real world data is the only way you will find the right mix for your application (it might end up being something in the middle like 4 jvms with 5 threads each).