带有Jetty的Java 8在linux内存问题上 [英] Java 8 with Jetty on linux memory issue

查看:142
本文介绍了带有Jetty的Java 8在linux内存问题上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮我解决以下问题:



背景:



<我们正在尝试将当前在生产中使用Java6(在Glassfish上)运行的现有应用程序迁移到Java8(在Jetty9上)设置。之前,我们能够在Java7上成功迁移相同的设置(在jetty9上)。但是客户现在决定使用Java 8。在此过程中,我们遇到了一些内存问题,以下是详细信息:



问题描述:



启动Jetty服务器后,java进程的初始(RES)内存使用量约为5.5g。在运行应用程序一段时间之后,内存使用会慢慢启动并消耗机器上最大可用物理内存(8g),最终导致服务器/系统崩溃。



此问题只在linux环境中遇到。在Windows环境中没有发现此类问题。



Profiler调查结果:



监控具有 VisualVM jconsole 的服务器。在两个分析器中,JVM的内存(堆和非堆)使用率都在分配的限制之下。



环境详细信息:

  Java版本:8 
服务器:Jetty 9.2.10
OS:虚拟机上的Linux(Linux版本2.6.32-279.14.1.el6 .x86_64(mockbuild@c6b8.bsys.dev.centos.org)(gcc版本4.4.6 20120305(红帽4.4.6-4)(GCC))#1 SMP Tue Tue Nov 6 23:43:09 UTC 2012
Java选项:
-Xms3072M

-server

-XX:+ UnlockDiagnosticVMOptions

-XX:+ LogVMOutput

-XX:+ UseG1GC

-XX:MaxGCPauseMillis = 75

-Xmx3072M

-Xss1024K

-XX:InitialCodeCacheSize = 192M

-XX:CodeCacheExpansionSize = 3M

-XX:CodeCacheMinimumFreeSpace = 3M

-XX:ReservedCodeCacheSize = 600M

-XX:MinMetaspaceExpansion = 3M

- XX:MaxMetaspaceExpansion = 18M

-XX:MaxMetaspaceSize = 500M

-XX:MaxDirectMemorySize = 288M

-XX:CompressedClassSpaceSize = 512M

-XX:ParallelGCThreads = 12

-XX:ConcGCThreads = 4

-Dsun.rmi.dgc.server.gcInterval = 86400000

-Dsun.rmi.dgc.client.gcInterval = 86400000

PS:请不要将此标记为重复。我已经在stackoverflow上阅读了很多答案,但没有解决或解决我的问题。



更新



我使用以下Java选项启动了jetty,从那以后内存使用量介于4.5g-4.8g(大约142小时)之间。它看起来很稳定。我通过java选项标志(Xmx& MetaspaceSize)保留了大约2g内存,但总是使用额外的2.5g内存。这是Linux机器上Java 8的正常行为吗?



使用的Java选项:

  -server 
-XX:+ UnlockDiagnosticVMOptions
-XX:+ LogVMOutput
-XX:LogFile = .. / logs / jvm.log

-XX:+ UseG1GC
-XX:MaxGCPauseMillis = 75
-XX:ParallelGCThreads = 12
-XX:ConcGCThreads = 12
-XX:+ PrintGCDetails
-XX :+ PrintGCTimeStamps
-Xloggc:../ logs / gc.log
-XX:NativeMemoryTracking = summary

-Xmx1500m
-Xss256k

-XX:MaxMetaspaceSize = 512m

-XX:+ HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath = / opt / logs / jetty.hprof

-Dsun.rmi .dgc.server.gcInterval = 86400000
-Dsun.rmi.dgc.client.gcInterval = 86400000

感谢您的时间!

解决方案

Java8 / 9中似乎是一个问题,因为它出现在Jetty中扫描jar并具有内存泄漏的annotations模块。参考。 https://github.com/eclipse/jetty.project/issues/575。我的解决方案(因为我不使用Jetty注释)是通过注释掉jetty / modules / annotations.mod中的行来禁用注释模块。因此,tie文件如下所示:

 
#Jetty Annotation扫描模块


[depend]
#Annotations需要加上,jndi功能
加上

[lib]
#Annotations需要jetty注释jars
lib /jetty-annotations-${jetty.version}.jar
#需要注释处理罐子
#lib / annotations / * .jar

[xml]
#启用注释扫描webapp配置
#etc / jetty-annotations.xml

编辑1 - 替代解决方案



关闭所有注释扫描可能过于激烈,它也会转变为jsp,因为它是依赖的。替代方案是提供使用模式限制扫描的Web应用程序上下文。将其保存在xml中,并将其与战争一起部署在webapps中,或将其包含在战争中。

 <配置类= org.eclipse.jetty.webapp.WebAppContext > 
< Set name =contextPath> / [myApp]< / Set>
< Set name =war> / [DIRECTORY] / [myApp [.war< / Set>
< Call name =setAttribute>
< Arg> org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern< / Arg>
< Arg> SCAN-NO-JARS< / Arg>
< / Call>
< /配置>


Can you please help me resolving the following issue:

Context:

We are trying to migrate our existing application which is currently running on Java6( on Glassfish) in production to Java8 (on Jetty9) setup. Earlier, We were able to successfully migrate the same setup on Java7(on jetty9). But the customer has decided to go with Java 8 now. In this process we have encountered some memory issues and below are the details:

Problem Description:

After starting the Jetty server, initial (RES)memory usage of java process is around 5.5g. After running the application for sometime the memory usage slowly shoots-up and consumes maximum available physical memory(8g) on the machine, eventually crashing the server/system.

This issue is encountered only on the linux environment. No such issues are found on Windows environment.

Profiler findings:

Monitored the server with VisualVM and jconsole. In both the profilers JVM's memory(heap & non-heap) usage is under the allocated limits.

Environment details:

Java Version :    8
Server       :     Jetty 9.2.10
OS           :    linux on a virtual machine(Linux version 2.6.32-279.14.1.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Tue Nov 6 23:43:09 UTC 2012
Java Options :        
        -Xms3072M

        -server

        -XX:+UnlockDiagnosticVMOptions

        -XX:+LogVMOutput

        -XX:+UseG1GC

        -XX:MaxGCPauseMillis=75

        -Xmx3072M

        -Xss1024K

        -XX:InitialCodeCacheSize=192M

        -XX:CodeCacheExpansionSize=3M

        -XX:CodeCacheMinimumFreeSpace=3M

        -XX:ReservedCodeCacheSize=600M

        -XX:MinMetaspaceExpansion=3M

        -XX:MaxMetaspaceExpansion=18M

        -XX:MaxMetaspaceSize=500M

        -XX:MaxDirectMemorySize=288M

        -XX:CompressedClassSpaceSize=512M

        -XX:ParallelGCThreads=12

        -XX:ConcGCThreads=4

        -Dsun.rmi.dgc.server.gcInterval=86400000

        -Dsun.rmi.dgc.client.gcInterval=86400000

PS: Please don't mark this as duplicate. I have read many answers on stackoverflow, but nothing addressed or solved my issue.

Update

I started jetty with the following Java Options, and since then the memory usage is between 4.5g-4.8g (approximately 142 hours). It looks stable to me. I reserved around 2g of memory through java option flags(Xmx & MetaspaceSize), but additional 2.5g is used always. Is this normal behavior for Java 8 on a linux machine?

Java Options used:

-server
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../logs/jvm.log

-XX:+UseG1GC
-XX:MaxGCPauseMillis=75
-XX:ParallelGCThreads=12
-XX:ConcGCThreads=12
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-Xloggc:../logs/gc.log
-XX:NativeMemoryTracking=summary

-Xmx1500m
-Xss256k

-XX:MaxMetaspaceSize=512m

-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/opt/logs/jetty.hprof

-Dsun.rmi.dgc.server.gcInterval=86400000
-Dsun.rmi.dgc.client.gcInterval=86400000

Thanks for your time!

解决方案

It seems to be an issue in Java8/9 that manifests itself in Jetty due to the annotations module that scans the jars and has a memory leak. Ref. https://github.com/eclipse/jetty.project/issues/575. A solution for me (because I do not use Jetty annotations) is to disable the annotations module by commenting out the lines in jetty/modules/annotations.mod. So tie file looks like this:

#
# Jetty Annotation Scanning Module
#

[depend]
# Annotations needs plus, and jndi features
plus

[lib]
# Annotations needs jetty annotation jars
lib/jetty-annotations-${jetty.version}.jar
# Need annotation processing jars too
#lib/annotations/*.jar

[xml]
# Enable annotation scanning webapp configurations
#etc/jetty-annotations.xml

Edit 1 - Alternative solution

Switching off all annotation scanning can be too drastic, it turns of jsp as well because it is dependent. The alternative is to provide a web application context which restricts the scanning using a pattern. Save this in an xml and deploy it in the webapps together with the war or include it in the war.

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
   <Set name="contextPath">/[myApp]</Set>
   <Set name="war">/[DIRECTORY]/[myApp[.war</Set>
   <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
      <Arg>SCAN-NO-JARS</Arg>
    </Call>
</Configure>

这篇关于带有Jetty的Java 8在linux内存问题上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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