java - GC 日志中的负期望幸存者大小

标签 java performance garbage-collection jvm out-of-memory

我正在开发一个完全用 Java 编写的内存数据库。我们有一个输入源,它为系统提供数据,这是提取/加载阶段。在运行它时,我注意到 JVM 挂起,根本原因是 Full GC 被触发。然后应用程序被卡住,随后出现 OutOfMemory 错误(超出 GC 开销限制)

检查 GC 日志发现了很多新旧垃圾收集。 令人惊讶的一件事是 Desired Survivor 大小为负数。我试图理解为什么会这样?有没有人遇到过这个?

环境:

  • Windows7 Professional Service Pack1
  • 戴尔 Precision T7500,24 核
  • 64 位操作系统 192 GB 内存

  • Sun JDK 版本:
    1.7.0_13-b20(64 位)

    JVM 设置:
  • -Xmx100g
  • -Xms100g
  • -详细:gc
  • -Xloggc:C:/temp/logs/gc.log
  • -XX:+PrintGCTimeStamps
  • -XX:+PrintGC详细信息
  • -XX:+PrintTenuringDistribution
  • -XX:MaxPermSize=256m
  • -XX:+UseParallelOldGC

  • GC 日志摘录(这不是完整的日志):

    0.666: [GC Desired survivor size 178913280 bytes, new threshold 7 (max 15) [PSYoungGen: 524289K->4431K(30583488K)] 524289K->4503K(100488576K), 0.0052536 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]

    0.671: [Full GC (System) [PSYoungGen: 4431K->0K(30583488K)] [ParOldGen: 72K->4096K(69905088K)] 4503K->4096K(100488576K) [PSPermGen: 8852K->8847K(21248K)], 0.0853597 secs] [Times: user=0.08 sys=0.00, real=0.09 secs]

    12.306: [GC Desired survivor size 178913280 bytes, new threshold 7 (max 15) [PSYoungGen: 26214464K->389676K(30583488K)] 26218560K->393868K(100488576K), 0.1907519 secs] [Times: user=0.69 sys=0.69, real=0.19 secs]

    19.845: [GC Desired survivor size 178913280 bytes, new threshold 7 (max 15) [PSYoungGen: 26604140K->4369012K(30583488K)] 26608334K->4539738K(100488576K), 2.0671426 secs] [Times: user=12.67 sys=10.64, real=2.07 secs]

    31.930: [GC Desired survivor size 178913280 bytes, new threshold 7 (max 15) [PSYoungGen: 30583476K->4368998K(30583488K)] 30764447K->5793376K(100488576K), 2.4316614 secs] [Times: user=14.32 sys=12.07, real=2.43 secs]

    43.950: [GC Desired survivor size 178913280 bytes, new threshold 7 (max 15) [PSYoungGen: 30583462K->4369018K(30583488K)] 32008283K->10474103K(100488576K), 3.0868838 secs] [Times: user=31.76 sys=10.64, real=3.09 secs]

    57.851: [GC Desired survivor size -954466304 bytes, new threshold 6 (max 15) [PSYoungGen: 30583482K->4369011K(16019904K)] 36688571K->19053916K(85924992K), 5.0616910 secs] [Times: user=45.58 sys=21.95, real=5.06 secs]

    67.849: [GC Desired survivor size -954466304 bytes, new threshold 5 (max 15) [PSYoungGen: 16019891K->7854065K(23301696K)] 30706222K->22540396K(93206784K), 1.9574226 secs] [Times: user=35.38 sys=0.00, real=1.96 secs]

    74.940: [GC Desired survivor size -954466304 bytes, new threshold 4 (max 15) [PSYoungGen: 19504945K->11650800K(23301696K)] 34191281K->27450594K(93206784K), 3.2089939 secs] [Times: user=54.41 sys=1.51, real=3.21 secs]

    83.683: [GC Desired survivor size -954466304 bytes, new threshold 3 (max 15) [PSYoungGen: 23301680K->11650785K(23301696K)] 39101518K->32434323K(93206784K), 4.8105989 secs] [Times: user=65.82 sys=10.30, real=4.81 secs]

    93.647: [GC Desired survivor size -954466304 bytes, new threshold 2 (max 15) [PSYoungGen: 23301665K->10083445K(23301696K)] 44085203K->35191108K(93206784K), 3.9481522 secs] [Times: user=54.77 sys=8.02, real=3.95 secs]

    102.406: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 21734325K->10417779K(23301696K)] 46841988K->39667600K(93206784K), 4.7031362 secs] [Times: user=63.29 sys=9.50, real=4.70 secs]

    112.109: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 22068659K->5501380K(23301696K)] 51318480K->45289996K(93206784K), 5.6499475 secs] [Times: user=51.39 sys=23.81, real=5.65 secs]

    122.858: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 17152260K->5829244K(23301696K)] 56941300K->51036174K(93206784K), 3.9348524 secs] [Times: user=47.49 sys=11.48, real=3.93 secs]

    132.599: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 17480124K->4411050K(23301696K)] 62703442K->55124929K(93206784K), 3.2682313 secs] [Times: user=35.46 sys=10.86, real=3.27 secs]

    141.869: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 16061930K->5983419K(23301696K)] 66775809K->61080627K(93206784K), 3.1660854 secs] [Times: user=38.39 sys=9.45, real=3.17 secs]

    149.996: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 17634299K->5335607K(23301696K)] 72731507K->65656597K(93206784K), 4.4767380 secs] [Times: user=55.41 sys=12.67, real=4.48 secs]

    154.473: [Full GC [PSYoungGen: 5335607K->0K(23301696K)] [ParOldGen: 60320990K->29187977K(69905088K)] 65656597K->29187977K(93206784K) [PSPermGen: 53148K->53088K(106560K)], 55.6080316 secs] [Times: user=518.19 sys=3.43, real=55.61 secs]

    210.083: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 1942K->96K(23301696K)] 29189919K->29188073K(93206784K), 0.0512343 secs] [Times: user=0.50 sys=0.00, real=0.05 secs]

    210.134: [Full GC [PSYoungGen: 96K->0K(23301696K)] [ParOldGen: 29187977K->29187816K(69905088K)] 29188073K->29187816K(93206784K) [PSPermGen: 53088K->53087K(106624K)], 15.5128928 secs] [Times: user=236.31 sys=0.19, real=15.51 secs]

    239.525: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 11650880K->4622965K(23301696K)] 40838696K->33810782K(93206784K), 1.2739696 secs] [Times: user=23.01 sys=0.00, real=1.27 secs]

    248.572: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 16273845K->4009690K(23301696K)] 45461663K->37894227K(93206784K), 2.3307283 secs] [Times: user=41.84 sys=0.00, real=2.33 secs]

    256.854: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 15660570K->5707092K(23301696K)] 49545113K->43643553K(93206784K), 2.5595566 secs] [Times: user=46.05 sys=0.00, real=2.56 secs]

    265.471: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 17357972K->4996932K(23301696K)] 55294440K->48690372K(93206784K), 2.8941178 secs] [Times: user=52.21 sys=0.00, real=2.89 secs]

    275.795: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 16647812K->3781542K(23301696K)] 60342280K->52491436K(93206784K), 2.6240427 secs] [Times: user=47.18 sys=0.00, real=2.63 secs]

    284.083: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 15432422K->5815192K(23301696K)] 64142316K->58360954K(93206784K), 2.3724770 secs] [Times: user=42.68 sys=0.00, real=2.37 secs]

    291.659: [GC Desired survivor size -954466304 bytes, new threshold 1 (max 15) [PSYoungGen: 17466072K->5357588K(23301696K)] 70011840K->63780322K(93206784K), 3.0063028 secs] [Times: user=54.20 sys=0.00, real=3.01 secs]

    299.322: [GC Desired survivor size -1228210176 bytes, new threshold 2 (max 15) [PSYoungGen: 17008468K->6341939K(23301696K)] 75431206K->70078817K(93206784K), 4.1999305 secs] [Times: user=65.35 sys=5.13, real=4.20 secs]

    303.523: [Full GC [PSYoungGen: 6341939K->0K(23301696K)] [ParOldGen: 63736877K->38098305K(69905088K)] 70078817K->38098305K(93206784K) [PSPermGen: 53125K->53125K(103360K)], 41.2081882 secs]



    正如您在上面日志中的 57.851 秒所注意到的,我们有一个负的期望幸存者大小,我不确定为什么会这样?

    这看起来像内存泄漏吗?

    任何帮助将不胜感激。我还为堆附加了一个visualvm的快照
    Visual VM Heap Snapshot

    最佳答案

    是的,你的问题似乎是你有太多的 Activity 对象。
    “超出 GC 开销限制”意味着 GC 运行、花费了很长时间并且释放的很少。
    您可以调整一些旋钮来控制控制它的阈值,但这些不会帮助您提高性能。

    在创建内存密集型模拟(也是 100 - 120GB 最大堆)时,我遇到了完全相同的问题。
    我的解决方案是远离对象来存储数据,并将所有内容保留在原始 int[] 中。
    最终变成了一个名为 Banana 的新开源项目。 ,它支持一些原始数据结构。
    Banana 实际上是基于它自己的内存管理来构建数据结构,您可以获得完全动态的数据结构,而没有对象的开销。
    继续阅读项目维基,它记录了事情是如何工作的,并获得了示例代码和基准。

    关于java - GC 日志中的负期望幸存者大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17984422/

    相关文章:

    java - log4j appender 问题 - 无法打印调试、错误级别

    java - java程序中如何向shell脚本传递参数

    linux - 生产者-消费者模式不适合我们的应用程序?或者只是使用上的误解?

    c# - 自处理事件是否会阻止实例被垃圾收集?

    java - 在 Apache Felix 中运行的任务调度程序?

    java - 如何使用线程概念在倒数计时器中运行后台应用程序?

    c++ - 迭代超过 10GB+ 的二进制文件

    mysql - 恢复 InnoDB 表 : very very slow?

    python - 更正扩展模块中的循环垃圾收集

    javascript - 处理 Javascript 中的元组 : container data structures