生产服务器上的 Tomcat、PermGen 和重新部署

发布于 2024-09-15 14:17:44 字数 362 浏览 3 评论 0原文

看起来这

 MemoryError: PermGen space
 java.lang.OutOfMemoryError: PermGen space

是一个常见问题。您可以增加 Perm 空间的大小,但在 100 或 200 次重新部署后,它就会满。跟踪类加载器内存泄漏几乎是不可能的。

在生产服务器上使用 Tomcat(或另一个简单的 servlet 容器 - Jetty?)有哪些方法?每次部署解决方案后服务器都会重新启动吗?

您是否将一台 Tomcat 用于多个应用程序?

也许我应该在不同的端口(或嵌入式 Jetty)上使用许多 Jetty 服务器,并每次都取消部署/重新启动/部署?

It looks like

 MemoryError: PermGen space
 java.lang.OutOfMemoryError: PermGen space

is a common problem. You can Increase the size of your perm space, but after 100 or 200 redeploys it will be full. Tracking ClassLoader memory leaks is nearly impossible.

What are your methods for Tomcat (or another simple servlet container - Jetty?) on production server? Is server restart after each deploy a solution?

Do you use one Tomcat for many applications ?

Maybe I should use many Jetty servers on different ports (or an embedded Jetty) and do undeploy/restart/deploy each time ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

鹿港巷口少年归 2024-09-22 14:17:44

我放弃了使用 tomcat 管理器,现在总是关闭 tomcat 来重新部署。

我们在同一台服务器上运行两个 tomcat,并使用带有 mod_proxy_ajp 的 apache Web 服务器,以便用户可以通过相同的端口 80 访问这两个应用程序。这也很好,因为当 tomcat 关闭时,用户会看到 apache 服务不可用页面。

I gave up on using the tomcat manager and now always shutdown tomcat to redeploy.

We run two tomcats on the same server and use apache webserver with mod_proxy_ajp so users can access both apps via the same port 80. This is nice also because the users see the apache Service Unavailable page when the tomcat is down.

私藏温柔 2024-09-22 14:17:44

您可以尝试添加这些 Java 选项:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

这将启用 PermGen 空间中的垃圾收集(默认情况下关闭)并允许 GC 卸载类。此外,您应该使用其他地方提到的 -XX:PermSize=64m -XX:MaxPermSize=128m 来增加可用的 PermGen 数量。

You can try adding these Java options:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

This enables garbage collection in PermGen space (off by default) and allows the GC to unload classes. In addition you should use the -XX:PermSize=64m -XX:MaxPermSize=128m mentioned elsewhere to increase the amount of PermGen available.

执手闯天涯 2024-09-22 14:17:44

是的,确实,这是一个问题。我们在 Tomcat 服务器上运行三个 Web 应用程序:第 1 个使用 Web 应用程序框架、Hibernate 和许多其他 JAR,第 1 个使用 Web 应用程序框架、Hibernate 和许多其他 JAR。 2 使用 Hibernate 和一些 JAR,但没有。 3基本上是一个非常简单的JSP应用程序。

当我们部署没有。 1、我们总是重启Tomcat。否则 PermGen 空间错误很快就会困扰我们。 2号有时可以毫无问题地部署,但因为它经常在没有时发生变化。 1 也是如此,无论如何都会重新启动。 3号完全没有问题,并且可以根据需要经常部署,没有问题。

所以,是的,我们通常会重新启动Tomcat。但我们也期待 Tomcat 7,它应该可以处理许多隐藏在不同第三方 JAR 和框架中的内存/类加载器问题。

Yes indeed, this is a problem. We're running three web apps on a Tomcat server: No. 1 uses a web application framework, Hibernate and many other JARs, no. 2 uses Hibernate and a few JARs and no. 3 is basically a very simple JSP application.

When we deploy no. 1, we always restart Tomcat. Otherwise a PermGen space error will soon bite us. No. 2 can sometimes be deployed without problem, but since it often changes when no. 1 does as well, a restart is scheduled anyway. No. 3 poses no problem at all and can be deployed as often as needed without problem.

So, yes, we usually restart Tomcat. But we're also looking forward to Tomcat 7, which is supposed to handle many memory / class loader problems that are burried into different third-party JARs and frameworks.

眼睛会笑 2024-09-22 14:17:44

HotSpot 中的 PermGen 切换只会延迟问题,最终你还是会得到 OutOfMemoryError。

我们已经遇到这个问题很长时间了,到目前为止我找到的唯一解决方案是使用 JRockit。它没有 PermGen,所以问题就消失了。我们现在正在测试服务器上对其进行评估,自切换以来我们还没有遇到过任何 PermGen 问题。我还尝试在本地计算机上重新部署 20 多次,其中一个应用程序在第一次重新部署时出现此错误,一切都进展顺利。

JRockit 旨在集成到 OpenJDK 中,所以也许这个问题将来对于普通 Java 也会消失。

http://www.oracle.com/technetwork/middleware/jrockit/overview /index.html

而且它是免费的,与 HotSpot 具有相同的许可证:

https:// blogs.oracle.com/henrik/entry/jrockit_is_now_free_and

PermGen switches in HotSpot only delay the problem, and eventually you will get the OutOfMemoryError anyway.

We have had this problem a long time, and the only solution I've found so far is to use JRockit instead. It doesn't have a PermGen, so the problem just disappears. We are evaluating it on our test servers now, and we haven't had one PermGen issue since the switch. I also tried redeploying more than 20 times on my local machine with an app that gets this error on first redeploy, and everything chugged along beautifully.

JRockit is meant to be integrated into OpenJDK, so maybe this problem will go away for stock Java too in the future.

http://www.oracle.com/technetwork/middleware/jrockit/overview/index.html

And it's free, under the same license as HotSpot:

https://blogs.oracle.com/henrik/entry/jrockit_is_now_free_and

伴梦长久 2024-09-22 14:17:44

您应该启用 PermGen 垃圾收集。默认情况下,Hotspot VM 不会收集 PermGen 垃圾,这意味着所有加载的类文件永远保留在内存中。每个新部署都会加载一组新的类文件,这意味着您最终会用完 PermGen 空间。

You should enable PermGen garbage collection. By default Hotspot VM does NOT collect PermGen garbage, which means all loaded class files remain in memory forever. Every new deployment loads a new set of class files which means you eventually run out of PermGen space.

止于盛夏 2024-09-22 14:17:44

您使用的是哪个版本的 Tomcat? Tomcat 7 和 6.0.30 有许多功能可以避免这些泄漏,或者至少警告您这些泄漏的原因。

此演示文稿,作者:Mark Thomas SpringSource(以及长期的 Tomcat 提交者)在这个主题上非常有趣。

Which version of Tomcat are you using? Tomcat 7 and 6.0.30 have many features to avoid these leaks, or at least warn you about their cause.

This presentation by Mark Thomas of SpringSource (and longtime Tomcat committer) on this subject is very interesting.

三寸金莲 2024-09-22 14:17:44

仅供参考,有一个新版本的 Plumbr 工具,它也可以监视和检测永久生成泄漏。

Just of reference, there is a new version of Plumbr tool, that can monitor and detect Permanent Generation leaks as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文