Java Web应用程序中的内存泄漏 [英] Memory leak in a Java web application

查看:132
本文介绍了Java Web应用程序中的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Tomcat 7上运行的Java Web应用程序似乎有内存泄漏。在负载下(使用JConsole确定),应用程序的平均内存使用量随时间线性增加。在内存使用率达到稳定水平后,性能会显着下降。响应时间从~100ms到[300ms,2500ms],所以这实际上是导致实际问题。

I have a Java web application running on Tomcat 7 that appears to have a memory leak. The average memory usage of the application increases linearly over time when under load (determined using JConsole). After the memory usage reaches the plateau, performance degrades significantly. Response times go from ~100ms to [300ms, 2500ms], so this is actually causing real problems.

我的应用程序的JConsole内存配置文件:

使用VisualVM ,我发现至少有一半的内存被字符数组(即char [])使用,并且字符串的大多数(大致相同数量的每个,300,000个实例)是以下之一:分配失败,复制,小GC的结尾,所有这些似乎与垃圾收集通知有关。据我所知,应用程序根本不监视垃圾收集器。 VisualVM找不到任何这些字符串的GC根,所以我很难跟踪它。

Using VisualVM, I see that at least half the memory is being used by character arrays (i.e. char[]) and that most (roughly the same number of each, 300,000 instances) of the strings are one of the following: "Allocation Failure", "Copy", "end of minor GC", all of which seem to be related to garbage collection notification. As far as I know, the application doesn't monitor the garbage collector at all. VisualVM can't find a GC root for any of these strings, so I'm having a hard time tracking this down.

内存分析器堆转储:

我无法解释为什么内存使用量会如此高,但我有一个关于为什么性能一旦降低就会降级的理论。如果内存碎片化,应用程序可能需要很长时间才能分配连续的内存块来处理新请求。

I can't explain why the memory usage plateaus like that, but I have a theory as to why performance degrades once it does. If memory is fragmented, the application could take a long time to allocate a contiguous block of memory to handle new requests.

将此与内置的Tomcat服务器状态应用程序进行比较,内存增加并保持平稳,但不像我的应用程序那样达到高底线。它也没有大量无法访问的char []。

Comparing this to the built-in Tomcat server status application, the memory increases and levels off at, but doesn't hit a high "floor" like my application. It also doesn't have the high number of unreachable char[].

Tomcat服务器状态应用程序的JConsole内存配置文件:

内存分析器Tomcat服务器状态applicationp的堆转储:

这些字符串在哪里可以分配,为什么它们不被垃圾收集?是否存在可能影响此问题的Tomcat或Java设置?是否有可能影响此问题的特定软件包?

Where could these strings be allocated and why are they not being garbage collected? Are there Tomcat or Java settings that could affect this? Are there specific packages that could be affect this?

推荐答案

我从 tomcat中删除了以下JMX配置\\ bin\setenv.bat

set "JAVA_OPTS=%JAVA_OPTS% 
    -Dcom.sun.management.jmxremote=true 
    -Dcom.sun.management.jmxremote.port=9090
    -Dcom.sun.management.jmxremote.ssl=false
    -Dcom.sun.management.jmxremote.authenticate=false"

我再也无法获得详细的内存堆转储,但是内存配置文件看起来好多了:

I can't get detailed memory heap dumps anymore, but the memory profile looks much better:

24小时后,内存配置文件看起来相同:

24 hours later, the memory profile looks the same:

这篇关于Java Web应用程序中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆