Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded

Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded

问题描述:

本地爬虫服务抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded 导致服务起不来,查看日志发现加载了太多资源到内存,本地的性能也不好,gc时间消耗的较多。

解决方案:

增加参数,-XX:-UseGCOverheadLimit,关闭这个特性; 同时增加heap大小,-Xmx1024m。

Y分析:

OOM大家都知道,就是JVM内存溢出了,那GC overhead limit exceed呢?

GC overhead limt exceed检查是Hotspot VM 1.6定义的一个策略,通过统计GC时间来预测是否要OOM了,提前抛出异常,防止OOM发生。Sun 官方对此的定义是:“并行/并发回收器在GC回收时间过长时会抛出OutOfMemroyError。过长的定义是,超过98%的时间用来做GC并且回收了不到2%的堆内存。用来避免内存过小造成应用不能正常工作。“

GC overhead limit exceed HotSpot的实现:

bool  print_gc_overhead_limit_would_be_exceeded = false;

if  (is_full_gc) {

  if (gc_cost() > gc_cost_limit &&

    free_in_old_gen < (size_t) mem_free_old_limit &&

    free_in_eden < (size_t) mem_free_eden_limit) {

    // Collections, on average, are taking too much time, and

    //      gc_cost() > gc_cost_limit

    // we have too little space available after a full gc.

    //      total_free_limit < mem_free_limit

    // where

    //   total_free_limit is the free space available in

    //     both generations

    //   total_mem is the total space available for allocation

    //     in both generations (survivor spaces are not included

    //     just as they are not included in eden_limit).

    //   mem_free_limit is a fraction of total_mem judged to be an

    //     acceptable amount that is still unused.

    // The heap can ask for the value of this variable when deciding

    // whether to thrown an OutOfMemory error.

    // Note that the gc time limit test only works for the collections

    // of the young gen + tenured gen and not for collections of the

    // permanent gen.  That is because the calculation of the space

    // freed by the collection is the free space in the young gen +

    // tenured gen.

    // At this point the GC overhead limit is being exceeded.

    inc_gc_overhead_limit_count();

    if (UseGCOverheadLimit) {

      if (gc_overhead_limit_count() >=

          AdaptiveSizePolicyGCTimeLimitThreshold){

        // All conditions have been met for throwing an out-of-memory

        set_gc_overhead_limit_exceeded(true);

        // Avoid consecutive OOM due to the gc time limit by resetting

        // the counter.

        reset_gc_overhead_limit_count();

      } else {

        // The required consecutive collections which exceed the

        // GC time limit may or may not have been reached. We

        // are approaching that condition and so as not to

        // throw an out-of-memory before all SoftRef's have been

        // cleared, set _should_clear_all_soft_refs in CollectorPolicy.

        // The clearing will be done on the next GC.

        bool near_limit = gc_overhead_limit_near();

        if (near_limit) {

          collector_policy->set_should_clear_all_soft_refs(true);

          if (PrintGCDetails && Verbose) {

            gclog_or_tty->print_cr("  Nearing GC overhead limit, "

              "will be clearing all SoftReference");

          }

        }

      }

    }

    // Set this even when the overhead limit will not

    // cause an out-of-memory.  Diagnostic message indicating

    // that the overhead limit is being exceeded is sometimes

    // printed.

    print_gc_overhead_limit_would_be_exceeded = true;

 

  } else {

    // Did not exceed overhead limits

    reset_gc_overhead_limit_count();

  }

}

转载于:https://my.oschina.net/universsky/blog/1819417

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值