views:

548

answers:

1

The Machine is Dual-Core, the OS uses a Multi-Processor kernel. In order to run some performance assessments, I want to set the thread-affinity of the JVM to a single core. However, I am worried that I will get skewed performance measurements as the JVM may be unaware that it is now constrained to a single core, but still using multi-processor primitives for thread synchronization and garbage collection. While the garbage collector can be tuned from the command line, that's not possible for the thread synchronization.

Now, the JVM uses mostly(*) OS-threads for its threads. So maybe the question should be rather "Do OSes (Windows/Linux) use correct synchronization primitives in multithreaded applications that are constraint to using a single core by setting the thread-affinity of the corresponding process?"

(*) That's not precisely true on Windows, where the JVM spinns on its own before calling the OS. That behavior can be controlled via -XX:+UseSpinning and -XX:PreBlockSpin settings.

A: 

If you only set the affinity of the JVM, then the results will be skewed to some degree anyway. Even if the JVM acts 100% as if it runs on a single-core machine, the OS kernel and other user-space code will still make use of the additional cores. That means less context switching overhead, and therefore different performance characteristics.

I would just disable the second core. Assuming you're on windows XP: edit c:\boot.ini by adding

/onecpu

to the list of boot options and reboot the machine.

Wim Coenen