简体   繁体   English

使用嵌入式Jetty作为应用程序服务器时内存被阻止

[英]Memory blocked out when using embedded Jetty as application server

I am using embedded jetty as a Java application server, with maximum JVM memory set to 800MB. 我使用嵌入式jetty作为Java应用程序服务器,最大JVM内存设置为800MB。 I created a method to deploy and un-deploy web archives. 我创建了一种部署和取消部署Web存档的方法。 Every time I deploy a war with a basic hello world application the embedded application server uses approximately 200MB additional memory which causes an out of memory after I add the 4th web app. 每次我使用基本的hello world应用程序部署war时,嵌入式应用程序服务器会使用大约200MB的额外内存,这会在我添加第4个Web应用程序后导致内存不足。 Is this the expected behaviour for embedded Jetty when used as an application server? 这是嵌入式Jetty用作应用程序服务器时的预期行为吗?

@ManagedOperation
public boolean deployWebApp(String context, String pathToWar){
    boolean success = false;
    WebAppContext webctx = null;
    try{
        webctx = addWebApp(context, pathToWar);
        webctx.getTempDirectory();
        webctx.start();
        success = webctx.isRunning();
    } catch (Exception e) {
        e.printStackTrace();
        logger.log(Level.SEVERE, "Failed to startup webapp with webappcontext: ", webapps.get(context).getContextPath());           
    }
    return success;     
}

No, I use embedded Jetty and it doesn't use anything like that amount of memory. 不,我使用嵌入式Jetty,它不会使用任何类似的内存。

The best thing to do is create a heap dump and then use a tool like the Eclipse Memory Analyzer to analyse the heap and see what it is about the web apps that are consuming so much memory. 最好的办法是创建一个堆转储,然后使用Eclipse Memory Analyzer之类的工具来分析堆,看看它占用了大量内存的Web应用程序是什么。

The undeploy/deploy memory leak could be related to various known JRE ClassLoader pinning issues. 取消部署/部署内存泄漏可能与各种已知的JRE ClassLoader固定问题有关。

We've recently (as of the past 2 days!) added some pre-emptive preventers of this pinning to the server side classloader to allow the WebAppClassLoader to operate in a way that doesn't leak references to the ClassLoader. 我们最近(截至过去2天!)在服务器端类加载器中添加了一些预先防止这种固定的预防措施,以允许WebAppClassLoader以不泄漏对ClassLoader的引用的方式运行。

See: http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-util/src/main/java/org/eclipse/jetty/util/preventers 请参阅: http//git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-util/src/main/java/org/eclipse/jetty/util/preventers

These are all added to the server via the Server.addBean(Object) method. 这些都通过Server.addBean(Object)方法添加到服务器。

You might have some luck using these on your embedded server. 您可以在嵌入式服务器上使用这些运气。

After playing around with jconsole and going through each of the handlers in the contexthandlercollection, it was discovered the undeployed webapps were not deleting the securityhandlers and sessionhandlers, as result the perm gen kept growing. 在使用jconsole并通过contexthandlercollection中的每个处理程序之后,发现未部署的webapps没有删除securityhandler和sessionhandler,因此perm gen继续增长。

We programmatically deleted each of those handlers and we can see the perm gen memory reducing. 我们以编程方式删除了每个处理程序,我们可以看到perm gen内存减少。

this.getSessionHandler().stop();
this.getSessionHandler().destroy();
this.getSecurityHandler().stop();
this.getSecurityHandler().destroy();

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

相关问题 JMX使用Jetty作为嵌入式服务器启用我的应用程序 - JMX enabling my Application using Jetty as embedded server 使用嵌入式jetty服务器运行Web应用程序(WAR) - Running a web application (WAR) with embedded jetty server 如何在Eclipse中使用带有嵌入式WTP插件的Jetty服务器使用Web套接字编写客户端服务器应用程序 - How to write client server application with web sockets using jetty server with embedded wtp plugin in eclipse 在以编程方式配置的Jetty嵌入式服务器中使用HttpRequestHandlerServlet - Using HttpRequestHandlerServlet in programatically configured Jetty embedded server 连接池用尽了连接。 在Jetty嵌入式服务器中使用DBCP2 BasicDataSource - Connection Pool running out of connection. Using DBCP2 BasicDataSource in Jetty embedded server 从jar启动时,gradle构建的嵌入式jetty应用程序始终返回500(内部服务器错误) - Embedded jetty application built by gradle always returns a 500 (internal server error) when launched from jar 使用Jetty服务器的Swagger应用程序 - Swagger application using Jetty server 使用模块系统时嵌入式 Jetty 中的 ClassNotFoundException - ClassNotFoundException in embedded Jetty when using Module system 嵌入式码头应用 - Embedded Jetty application 带有嵌入式Jetty服务器的球衣 - Jersey with embedded Jetty server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM