根据这个问题的动机:Error java.lang.OutOfMemoryError: GC overhead limit exceeded
最近我和某人就这个错误进行了辩论。
在我的理解中,这个错误本身不能被视为 JVM 失败的“首要”原因。
我的意思是,广泛的垃圾收集本身并不是失败的原因。大量的垃圾收集总是由非常少的可用内存量引起的,这会导致频繁的 GC 调用(核心原因可能是内存泄漏)。
如果我正确理解了对手的立场,他认为系统中产生了很多符合GC条件的小对象,导致它们被频繁回收,导致了这个错误。所以问题不是内存泄漏或低内存限制,而是 GC 调用频率本身。
这里是我们有不同观点的地方。
在我看来,您的流程产生多少符合 GC 条件的小对象并不重要(即使它不是一个好的设计,您可能应该尽可能减少这个数量)。如果你有足够的内存,并且没有明显的内存泄漏,那么在某个时候 GC 会收集大部分这样的对象,所以这应该不是问题。至少这不会导致系统崩溃。
简要回顾一下我的立场:如果您GC overhead limit exceeded,那么要么是内存泄漏,要么只是需要增加内存限制。
简要回顾一下我的对手的立场:如果你产生了很多符合 GC 条件的小对象,这已经是一个问题,因为它本身会导致 GC 开销限制超出。
我是不是错了,错过了什么?
最佳答案
- 部分回答 -
请注意,我使用 OpenJDK (JDK 9) 源作为基础来评论这个问题。这个答案不依赖于任何类型的文档或已发布的规范,并且包含一些来 self 对源代码的理解和解释的推测。
GC overhead limit exceeded 在 VM 中被视为内存不足错误的子类型,并在尝试分配内存失败后生成(参见 (a))。
本质上,VM 跟踪完全垃圾收集 的发生次数,并将其与为完全 GC 强制执行的限制进行比较(可以使用 -XX:GCTimeLimit= 在 Hotspot 上配置,参见 Garbage Collector Ergonomics )。
如何跟踪完整 GC 计数的实现以及检测到 GC 开销限制时背后的逻辑在一个地方可用,在 hotspot/src/share/vm/gc/shared/adaptiveSizePolicy.cpp 中。 .如您所见,为了满足 GC 开销限制的标准,需要满足老年代和伊甸园中可用内存的两个附加条件:
void AdaptiveSizePolicy::check_gc_overhead_limit(
size_t young_live,
size_t eden_live,
size_t max_old_gen_size,
size_t max_eden_size,
bool is_full_gc,
GCCause::Cause gc_cause,
CollectorPolicy* collector_policy) {
...
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 {
...
}
GC overhead limit exceeded 错误何时产生?它实际上不会在收集过程中发生,但是当 VM 尝试分配内存时 - 您可以在 hotspot/src/share/vm/gc/shared/collectedHeap.inline.hpp 中找到这些语句的理由。 :
HeapWord* CollectedHeap::common_mem_allocate_noinit(KlassHandle klass, size_t size, TRAPS) {
...
bool gc_overhead_limit_was_exceeded = false;
result = Universe::heap()->mem_allocate(size, &gc_overhead_limit_was_exceeded);
...
// Failure cases
if (!gc_overhead_limit_was_exceeded) {
report_java_out_of_memory("Java heap space");
...
} else {
report_java_out_of_memory("GC overhead limit exceeded");
...
}
查看 G1 实现的方法 mem_allocate(可以在 g1CollectedHeap.cpp 中找到),看起来 boolean 值 gc_overhead_limit_was_exceeded 是不再使用了。如果启用 G1 GC,我不会很快得出这样的结论:GC 内存开销错误不会再发生 - 我需要检查一下。
看来你是对的,这个错误确实是内存耗尽造成的;
根据收集小对象的次数可以产生这个错误的论点对我来说似乎不正确,因为
关于java - "GC overhead limit exceeded"是失败的次要原因吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49303173/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www