如何告诉 Hotspot JVM 是使用单处理器还是多处理器线程同步?
该机器是双核的,操作系统使用多处理器内核。 为了运行一些性能评估,我想将 JVM 的线程亲和性设置为单个核心。 然而,我担心我会得到不准确的性能测量结果,因为 JVM 可能不知道它现在仅限于单核,但仍然使用多处理器原语进行线程同步和垃圾收集。 虽然可以从命令行调整垃圾收集器,但这对于线程同步是不可能的。
现在,JVM 的线程主要使用 (*) 操作系统线程。 因此,也许问题应该是“操作系统(Windows/Linux)是否在多线程应用程序中使用正确的同步原语,这些应用程序通过设置相应进程的线程亲和性来限制使用单个核心?”
(*) 在 Windows 上情况并非如此,在 Windows 上,JVM 在调用操作系统之前会自行旋转。 该行为可以通过 -XX:+UseSpinning 和 -XX:PreBlockSpin 设置来控制。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果只设置JVM的亲和力,那么结果无论如何都会有一定程度的偏差。 即使 JVM 100% 就像在单核机器上运行一样,操作系统内核和其他用户空间代码仍然会使用额外的内核。 这意味着上下文切换开销更少,因此具有不同的性能特征。
我会禁用第二个核心。 假设您使用的是 Windows XP:通过添加
到 启动选项并重新启动计算机。
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 addingto the list of boot options and reboot the machine.