- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法在 JVM 中强制/重现 FullGC x 秒?基本上我需要这个来验证某些基于心跳的应用程序(zookeeper 的客户端)中问题的根本原因
编辑:unix命令kill -STOP <pid>
和 kill -CONT <pid>
模拟 FullGC(停止世界行为)?
最佳答案
您可以在 HotSpot JVM 上模拟一个非常长的 stop-the-world 事件,从用户的角度来看,它类似于 FullGC。
HotSpot 不放 safepoints进入计数的 int 循环,因为它假定它们将“足够快”地终止(在这种情况下,服务器编译器将生成更优化的循环代码)。即使是停止世界也必须等到这个循环结束。在下面的例子中,我们有一个非常紧凑的循环,它在没有安全点轮询的情况下进行小而昂贵的计算:
public static double slowpoke(int iterations) {
double d = 0;
for (int j = 1; j < iterations; j++) {
d += Math.log(Math.E * j);
}
return d;
}
为了像暂停一样重现 FullGC,你可以使用这样的东西:
public class SafepointTest {
public static double slowpoke(int iterations) {
double d = 0;
for (int j = 1; j < iterations; j++) {
d += Math.log(Math.E * j);
}
return d;
}
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread() {
@Override
public void run() {
double sideEffect = 0;
for (int i = 0; i < 10000; i++) {
sideEffect = slowpoke(999999999);
}
System.out.println("result = " + sideEffect);
}
};
thread.start();
new Thread(){
@Override
public void run() {
long timestamp = System.currentTimeMillis();
while (true){
System.out.println("Delay " + (System.currentTimeMillis() - timestamp));
timestamp = System.currentTimeMillis();
//trigger stop-the-world
System.gc();
}
}
}.start();
thread.join();
}
}
结果:
Delay 5
Delay 4
Delay 30782
Delay 21819
Delay 21966
Delay 22812
Delay 22264
Delay 21988
为了增加延迟,只需更改 slowpoke(int iterations)
函数的参数值即可。
这是有用的诊断命令:
-XX:+PrintGCApplicationStoppedTime
这实际上会将所有安全点的暂停时间报告到 GC 日志中。不幸的是,此选项的输出缺少时间戳。-XX:+PrintSafepointStatistics –XX:PrintSafepointStatisticsCount=1
这两个选项将强制 JVM 在每个安全点后报告原因和时间。关于编辑:从用户的角度来看,kill -STOP
和 kill -CONT
与 STW 具有相同的语义,即应用程序不响应任何请求。但是,这需要访问命令行并且不消耗资源(CPU、内存)。
关于java - 如何在 JVM 中强制/重现 Full GC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33917951/
这是在 https://stackoverflow.com/questions/12639454/make-scalacheck-tests-deterministic 中作为“奖金问题”提出的,但没
我的项目使用 Angular 6 和 Leaflet 1.2。 我想重现当用户在 Leaflet map 上保持右键或左键单击时的拖动效果。例如,我希望在不断按下空格键时能够开始拖动 map 。 我已
我们正在将我们的用户身份验证从提供的 .NET 实现迁移到我们自己的系统。 我们希望能够支持存在于 aspNet_Membership 表中的旧密码。 Password 和 Salt 位于该表中,因此
我有一个二进制文件,它在 99% 的时间里都运行良好。有时,我无法理解,它会因这个输出而崩溃。在我重新启动之后,一切正常。 二进制是一个模板系统。它读取了一些带有占位符的模板,例如{%foo%} 或
我试图在 c 中重现 strcpy 的行为,我的问题是该函数有效但它在末尾附加了额外的东西。 char *ft_strcpy(char * dst, const char * src) { in
我最近遇到了可怕的 UserPreferenceChanged 事件 UI 卡住问题,随后我解决了可能的原因,例如: 调用单个控件而不是主应用程序表单(参见 https://stackoverflow
在 Scala 编程中,我可以读到 ==运算符的行为就像是这样定义的: final def == (that: Any): Boolean = if (null eq this) {null eq t
我正在和我的 friend 一起开发 Django 项目。该项目依赖于一些 python 模块。我在 virtualenv 中安装了 django 和其他依赖项。 django 项目的代码位于一个存储
关于spark的大多数问题都使用show作为代码示例,没有生成数据帧的代码,如下所示: df.show() +-------+--------+----------+ |USER_ID|locatio
我正在尝试重现 java.lang.OutOfMemoryError: unable to create new native thread但是使用 -Xss VM 参数。我猜想如果我们有大量线程,并
我正在尝试在自定义 alertView 中插入表格 View 。我需要实现与默认警报相同的样式。从 Debug View Hierarchy 我几乎复制了样式,但我无法弄清楚 Apple 如何设置模糊
标准是否保证如果 std::mt19937 被相同的数字播种,它会在所有平台上产生相同的数字序列? 换句话说,它的实现是否由标准明确定义,或者像 std::rand() 一样被视为实现细节? 最佳答案
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的
我有一个网站可以从 BingPreview/1.0b* 获得访问,这很可能是 Bing 的机器人。 我收到一个错误,它似乎无法找到我非常确定应该存在的 DOM 元素。我没有从任何其他浏览器(在所有主要
有谁知道如何重现 new Notes new scanning feature在 iOS 11 中?? AVFoundation 是否用于相机? 摄像头如何检测纸张/文档/卡片的形状? 他们如何实时放
您好! 作为使用 Objective-C 开发 iPhone 应用程序的初学者,我想知道重新创建 iPhone SMS 应用程序 UI(带有消息气泡等的用户界面)的最简单方法是什么 我考虑过将 UIT
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: How can the built-in range function take a single argu
虽然这很可能是我自己犯的错误,但有人可以帮助我。我有一个包含 6 个数据点的极坐标图,在绘制时仅显示 5 个数据点。如果这是一个问题,我会在 GitHub 上打开 1,但我在想,如果它归结于我糟糕的代
我正在尝试使用 rCharts 重现简单的示例绘图库 sankey图表。我发现this example from scratch并尝试重现它,但是,我遇到了一些问题。 首先,我尝试在没有任何内容的情况
进入 Haskell,我试图重现 numpy's reshape 之类的东西与列表。具体来说,给定一个平面列表,将其 reshape 为一个 n 维列表: import numpy as np a =
我是一名优秀的程序员,十分优秀!