JVM Tutorials - Herong's Tutorial Examples - Version 4.23, by Dr. Herong Yang
Single Thread Process on 2-CPU-4-Thread Machine
This section provides a tutorial example on how a single-threaded process behaves on a 2-CPU-4-Thread architecture. Windows will only allocate a total of 1 CPU-Thread to the process.
To get further understanding of the performance impact of the CPU architecture, let's try the following tests my Intel Core i5-2520M, which is a 2-CPU-4-Thread architecture.
First, let's play with a single-thread process only.
1. Close all applications on the system.
2. Launch MultithreadingCpuRunner.java with 1 thread.
C:\>"\Program Files\Java\jdk1.7.0_45\bin\java" MultithreadingCpuRunner 1000 1 Thread parameter: 1000 Number of threads: 1 Seconds | Productivity per thread | Total | Average ... 181 | 883 | 883 | 885 182 | 890 | 890 | 885 183 | 886 | 886 | 885 184 | 882 | 882 | 885 185 | 888 | 888 | 885 ...
3. View individual CPU-Thread usage on the Performance tab of Task Manager. You will see that the running process is being distributed between 2 CPU-Threads with 2 other CPU-Threads doing nothing:
CPU-Thread 1 - 85% used (approximately) CPU-Thread 2 - 0% used CPU-Thread 3 - 15% used (approximately) CPU-Thread 4 - 0% used
4. View total CPU usage on the Performance tab of Task Manager.
You will that the total CPU usage is about 24%.
See the picture below:
Question: Why the JVM is not make full use of all 4 CPU-Threads? I have no idea.
5. Force Windows to use only 1 CPU-Thread by going to the
on the Processes tab of Task Manager.
Then right-mouse click on the "java.exe" process, which represents the running
When select "Set Affinity...", you will see the processor affinity options.
Uncheck CPU 1, 2, and 3. Then click OK to force Windows to only use CPU-Thread 0
for the execution of MultithreadingCpuRunner.java.
See the picture below:
6. Go back to view individual CPU-Thread usage on the Performance tab of Task Manager again. You will see that the running process is being distributed only to the first CPU-Thread:
CPU-Thread 1 - 100% used CPU-Thread 2 - 0% used CPU-Thread 3 - 0% used CPU-Thread 4 - 0% used
This behavior is expected, because we asked the Windows to only use the first CPU-Thread. Of course, the overall performance is not changed:
Seconds | Productivity per thread | Total | Average ... 1163 | 885 | 885 | 885 1164 | 892 | 892 | 885 1165 | 889 | 889 | 885 1166 | 880 | 880 | 885 1167 | 891 | 891 | 885 ...
Conclusion: By default, Windows distributes a single process to more than one CPU-Threads to execute. But the it will only allocate a total of a single CPU-Thread power to the process. For example, Windows will allocate 25% of total CPU power to a single-threaded process on a 4-CPU-Thread machine.
Last update: 2014.
Table of Contents