简体   繁体   English

如何使用Jconsole计算吞吐量

[英]How to calculate throughput with Jconsole

Is there a way to calculate the Garbage Collection throughput for a given time slot of a Java program using the JConsole interface? 有没有一种方法可以使用JConsole接口针对Java程序的给定时隙计算垃圾收集吞吐量? For example, I want to compare different functionalities in a program and how GC throughput varies between these. 例如,我想比较程序中的不同功能以及这些之间的GC吞吐量如何变化。

I have read the Oracle JConsole docs and the closest metric I can find is GC Time which is: 我已经阅读了Oracle JConsole文档,最接近的指标是GC时间,即:

"GC time: the cumulative time spent on garbage collection and the total number of invocations. It may have multiple rows, each of which represents one garbage collector algorithm used in the Java VM." “ GC时间:花费在垃圾收集上的累积时间和调用总数。它可能有多行,每一行代表Java VM中使用的一种垃圾收集器算法。”

Source: https://docs.oracle.com/javase/8/docs/technotes/guides/management/jconsole.html 来源: https : //docs.oracle.com/javase/8/docs/technotes/guides/management/jconsole.html

But this doesn't specify a start time for when it starts accumulating. 但这并没有指定开始累积的开始时间。 If I could identify when this starts I could calculate throughput myself. 如果我可以确定何时开始,则可以自己计算吞吐量。

Or alternatively is there any other way to calculate throughput on JConsole? 或者,是否有其他方法可以在JConsole上计算吞吐量?

I usually use two: 我通常使用两个:

  1. GCViewer GCViewer
  2. gceasy gceasy

simultaneously, because different tools could show different results. 同时,因为不同的工具可能会显示不同的结果。

For your question the answer - GC logs enabled from the start of application. 对于您的问题,答案-从应用程序开始启用了GC日志。 So when you see GC time, you could get throughput = sum(GC time)/Total time. 因此,当您看到GC时间时,您可以得到吞吐量=总和(GC时间)/总时间。

By GC logs enabled, do you mean using -verbose:gc or -Xloggc: ? 通过启用GC日志,您的意思是使用-verbose:gc或-Xloggc:吗?

No, I mean internal counters . 不,我是说内部柜台 It is good to clarify. 有必要澄清一下。

Also: do you know what GC time represents: the time from when the application was started, or the time per a given time period? 另外:您是否知道GC时间代表什么:启动应用程序的时间或每个给定时间段的时间?

From start of application. 从申请开始。 Another approach to see GC time using jstat . 使用jstat查看GC时间的另一种方法。 Let would we have this program: 让我们有这个程序:

public class JStatTest {

    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 10; ++i) {
            System.gc();
            System.out.println("Wait...");
            Thread.sleep(1000);
        }
        Thread.sleep(100_000);
    }

}

We can connect with jstat (from start) and jconsole (near to end, after cycle) and see this: 我们可以连接jstat(从开始)和jconsole(从头到尾,在循环之后),然后看到:

在此处输入图片说明

This is without enabled GC verbose logging. 没有启用GC详细日志记录。

To see total time: 要查看总时间:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM