简体   繁体   English

Apache HttpComponents EntityUtils内存泄漏?

[英]Apache HttpComponents EntityUtils memory leak?

I executed a 12-hour load test on my Java servlet-based server (Java 1.7 running under WebLogic 12 and Oracle Enterprise Linux). 我在基于Java Servlet的服务器(在WebLogic 12和Oracle Enterprise Linux下运行的Java 1.7)上执行了12小时的负载测试。 After test has finished, I observed that the memory consumption gradually went up from 500Mb in the beginning of the test to around 3.5Gb (and fluctuated there +/- 500Mb for several hours). 测试完成后,我发现内存消耗从测试开始时的500Mb逐渐增加到大约3.5Gb(并在+/- 500Mb的范围内波动了几个小时)。 3 days later (server was doing nothing during these 3 days) - I examined memory again, and noticed that nothing out of these 3.5Gb was freed. 3天后(服务器在这3天内没有执行任何操作)-我再次检查了内存,并发现3.5Gb中的任何内容都没有释放。

To make sure GC is executing, I mad explicit GC using jcmd: 为了确保GC正在执行,我使用jcmd疯狂进行了显式GC:

  • GC.run GC运行
  • GC.run_finalization GC.run_finalization
  • GC.run GC运行

Then, I made a heap snapshot and analyzed with YourKit analyzer (same results with jvisualvm as well). 然后,我制作了一个堆快照,并使用YourKit分析器进行了分析(与jvisualvm相同的结果)。

I noticed that I have 2.5Gb of "Unreachable" objects still being there after 3 days of inactivity. 我注意到在闲置3天后,仍有2.5Gb的“无法访问”对象仍然存在。 A typical object's incoming references look like this (I'm having ~700K of such objects): 典型对象的传入引用如下所示(我有约700K的此类对象):

在此处输入图片说明

I examined Apache HttpComponents code (HttpCore version 4.3.2), and I noticed the following strange code in EntityUtils.toString (which I'm using in my server): 我检查了Apache HttpComponents代码(HttpCore版本4.3.2),然后在EntityUtils.toString(我在服务器中使用的代码)中注意到以下奇怪的代码:

在此处输入图片说明

It looks to me that since reader object is not closed - it can create references, eventually causing the leaks I'm observing. 在我看来,由于没有关闭读者对象-它可以创建引用,最终导致我观察到的泄漏。

  • Is this a leaky code of Apache HttpCore EntityUtils? 这是Apache HttpCore EntityUtils的泄漏代码吗?
  • Any other reason to have so many unreachable objects after 3 days and after GC.run? 还有3天和GC.run之后有这么多无法到达的对象的其他原因吗?

Thank you. 谢谢。

Consider extending AsyncCharConsumer as shown here to produce a string with response content or using a HttpAsyncResponseConsumer if need a more sophisticated response processing. 考虑延长AsyncCharConsumer如图所示这里生产具有响应内容或使用字符串HttpAsyncResponseConsumer如果需要更复杂的响应处理。

EntityUtil methods are generally intended for entities backed by a blocking InputStream . EntityUtil方法通常用于由阻塞InputStream支持的实体。 And even then I would generally recommend consuming entity content directly from the content stream instead of converting it to a string. 即使那样,我通常还是建议直接从内容流中使用实体内容,而不是将其转换为字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM