Java 中的分析是否会带来其自身的性能问题?

Does profiling in Java bring its own performance issues?

我经常分析我团队的高性能 Java 程序,因为低效的功能会导致严重的速度下降。为此,我使用以下 Java 机器参数保持端口打开以附加 Java VisualVM:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9011 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost

今天让我印象深刻:对 Java 程序进行分析——或者只是为了分析而保持端口打开——会进一步降低速度吗?如果是这样,某些分析方法是否比其他方法成本更高?什么样的速度降低或开销——例如,1% 的运行时间,10% 的运行时间——是正常预期的?

虽然我的问题是针对更广泛的 Java 观众,但我会注意到我们的程序 a 是记忆轻型但 CPU 密集型模拟:具体来说,有大量的永久进行的小但计算量大的函数调用。考虑到函数调用的绝对数量,也许在我们的例子中优化是昂贵的,但对其他人来说就更少了?

does profiling a Java program

大约 10% - 30%,具体取决于您在做什么。

or simply keeping a port open for the sake of profiling

可能几乎没有开销。

is memory-light but CPU-intensive simulation: specifically, there are an enormous number of small but computationally expensive function calls being perpetually made.

我会认真考虑 FlightRecorder(来自 Java 7,在 Java 8 中更好)。这有更低的开销,并且有更多的细节 CPU 记录。 IN Java 8 你可以 运行 它没有添加任何命令行参数。