gpt4 book ai didi

java - 如何对 java 垃圾收集器进行微基准测试?

转载 作者:行者123 更新时间:2023-11-29 07:48:56 25 4
gpt4 key购买 nike

我需要从 gc(垃圾收集)的角度测试存储域对象和索引的不同方法。

(与我的问题有关Will GC be much slower if i have mulitple references for each of millions of my business objects?)

这有什么意义吗?

long start = System.currentTimeMillis();
System.gc();
long time = start - System.currentTimeMillis();

如何正确地做到这一点?

最佳答案

不,这完全没有意义;看我的回答herethis question .

由于 GC 是非确定性,您只能真正测量一段时间内的平均值。

VisualVM有各种工具来监控 GC Activity 。新Mission Controlflight recorder 中拥有更强大的工具一套运行时分析工具。

请注意,飞行记录器需要附加许可条件的 -XX:+UnlockCommercialFeatures 标志:

COMMERCIAL FEATURES You may not use the Commercial Features for running Programs, Java applets or applications in your internal business operations or for any commercial or production purpose, or for any purpose other than as set forth in Sections B, C, D and E of these Supplemental Terms. If You want to use the Commercial Features for any purpose other than as permitted in this Agreement, You must obtain a separate license from Oracle.

基本上您不能在生产中使用商业功能。更多信息 here .

这将允许您测量这些东西和收集运行的数量,GC 的 CPU 使用率。创建对象数,对象引用数,清除数。

但问题仍然存在,GC 的运行是非确定性

您需要创建运行一段时间的真实世界测试套件。您需要从代码中收集指标,例如响应时间和监控端的指标。几个小时就好了。一天更好。

一旦你有了这个,你就可以相当确定哪个 GC 最适合你的应用程序。

关于java - 如何对 java 垃圾收集器进行微基准测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22878944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com