简体   繁体   English

设置Java服务器的堆大小的规则或准则

[英]Rules or guidelines for setting the heap size for java server

I'm not interested for a specific application or environment. 我对特定的应用程序或环境不感兴趣。 Although I'm facing this problem with my application deployment now, I'm interested in a more general solution. 尽管我现在在应用程序部署中遇到了这个问题,但我对更通用的解决方案感兴趣。

Are there some rules on how big to set the heap size on a java server? 关于在Java服务器上设置堆大小有多大的规则? (Especially now, I'm working with Tomcat 7 ). (特别是现在,我正在使用Tomcat 7 )。 With -Xms and -Xmx you can specify the minimum respectively maximum values for heap size. 使用-Xms-Xmx可以分别指定堆大小的最小值和最大值。 Based on the applications that are deployed on server, how to know what maximum and minimum heap size to set. 根据服务器上部署的应用程序,如何知道要设置的最大和最小堆大小。 Is there a generic way to find it, or is it more empirical, related to the deployed application(s) ? 有没有找到与已部署应用程序相关的通用方法? - by 'related to the deployed appliccation(s)' I mean that you must know what your application is doing, database work, user interface work, or any other memory consumer things. -“与已部署的应用程序相关”是指您必须知道应用程序在做什么, 数据库工作, 用户界面工作或任何其他内存使用程序

I have done java web app in several companies and for all of them it was completely empirical. 我已经在多家公司完成了Java Web应用程序,对于所有公司来说,这完全是凭经验进行的。 It was mostly depending on the machine, not on the application. 这主要取决于机器,而不取决于应用程序。 For example, if you have a machine with 4GB with only a tomcat server, then you allow it to take 3GB. 例如,如果您有一台只有Tomcat服务器的4GB机器,那么您允许它占用3GB。 If the server is low on memory, you try to fix it or you buy more memory... I think it's cheaper than paying someone to calculate the memory needed... 如果服务器的内存不足,请尝试修复它或购买更多的内存...我认为这比付钱给某人来计算所需的内存要便宜...

I think it is also like that in big companies, there's no secret... 我认为在大公司中也是如此,这不是秘密...

This is empirical - observe your application and see how it behaves. 这是经验性的-观察您的应用程序并查看其行为。

And there is more to it - for a starter, read about memory pools and how to size them . 还有更多内容-对于初学者来说,请阅读有关内存池及其大小的信息 If you get into it, look at http://www.javaperformancetuning.com/ - there's a lot of materials about tuning memory issues, and more. 如果您有兴趣,请访问http://www.javaperformancetuning.com/-有关调优内存问题的材料很多,还有更多内容。

Now, in the usual case, you should not bother with -Xms . 现在,在通常情况下,您不必理会-Xms Set -Xmx to whatever value your application needs (observe, to find out). -Xmx设置为您的应用程序需要的任何值(观察一下以了解)。 JVM increases the size of memory pools when it needs to, and decreases them accordingly. JVM会在需要时增加内存池的大小,并相应地减少它们。 Just make sure, you don't get OutOfMemoryError s. 只要确保您没有收到OutOfMemoryError And then, look into your application for memory bottlenecks (like, for example full GC's, or long stop-the-world phase), and size the pools and/or configure the GC if you need to. 然后,在您的应用程序中查找内存瓶颈(例如完整的GC或长时间停工阶段),并确定池的大小和/或根据需要配置GC。

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

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