简体   繁体   English

在tomcat中设置JVM内存选项?

[英]Setting JVM memory options in tomcat?

Is there any drawback setting the -Xms and -Xmx to the same value? 将-Xms和-Xmx设置为相同的值有什么缺点吗? And also -XX:MaxPermSize and -XX:PermSize to same value. 还有-XX:MaxPermSize和-XX:PermSize相同的值。

It is recommended here. 在这里推荐

If there enough physical memory available in server, is it recommended to set bit higher values to both options? 如果服务器中有足够的物理内存,是否建议为这两个选项都设置更高的值?

UPDATE: 更新:

Environment Java 1.6.0_45 in Solaris 10 Solaris 10中的环境Java 1.6.0_45

java version "1.6.0_45" Java版本“ 1.6.0_45”

Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java(TM)SE运行时环境(版本1.6.0_45-b06)

Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode) Java HotSpot(TM)64位服务器VM(内部版本20.45-b01,混合模式)

Setting -xms and -xmx was a good practice in older versions of Java, when adaptive sizing wasn't working good enough. 在Java的旧版本中,当自适应大小调整不能很好地工作时,设置-xms和-xmx是一种好的做法。 In Java >= 7 it works really nice, so it's no longer needed. 在Java> = 7中,它的工作非常好,所以不再需要它。 If you need more details you have to read about -XX:+UseAdaptiveSizePolicy flag or refer HotSpot documentation 如果需要更多详细信息,则必须阅读有关-XX:+UseAdaptiveSizePolicy标志或参考HotSpot文档。

Another thing you have to remember about is that you have 8GB RAM on your server doesn't mean that you can use it wholly for Java. 您还需要记住的另一件事是,服务器上有8GB RAM并不意味着您可以完全将其用于Java。 You have to left some for system buffers 你必须留下一些用于系统缓冲区

In Java <= 1.6 setting XMS=XMS and same in case of PermGen is reasonable, but you have to remember about correct tuning of the XMX value, because too much memory will cause cobra effect 在Java <= 1.6中,设置XMS = XMS以及在PermGen的情况下进行设置是合理的,但是您必须记住正确调整XMX值,因为过多的内存会导致眼镜蛇效应

  • Imagine the case when the two values are not same. 想象两个值不相同的情况。 In that case, JVM has the additional tasks of managing the heap size. 在这种情况下,JVM还有其他管理堆大小的任务 Increasing memory whenever needed, garbage collection (not true for PermGen resulting into shrinking the size of the heap. 只要需要,就增加内存,进行垃圾回收(对于PermGen而言并非如此,导致缩小堆大小。

  • Having said that, there are lot of other factor also play very important role. 话虽如此,还有很多其他因素也起着非常重要的作用。 For example, the way your application uses memory also determines the effect of heap size setting. 例如, 应用程序使用内存方式还决定了堆大小设置的效果。 Tor example, a calculation intensive standalone application will have a completely different memory requirement that a typical client-server e-commerce application which does a lot of I/O. 例如,计算密集型独立应用程序将具有与执行大量I / O的典型客户端服务器电子商务应用程序完全不同的内存需求

  • Another point to keep in mind is the underlying OS . 要记住的另一点是底层操作系统 The memory is finally allocated by OS to JVM on request and the way this happens differs from OS to OS. 操作系统最终根据请求将内存分配给JVM,这种情况发生的方式因操作系统而异。 The only way to address is to go through the documentation of the particular JVM implementation . 解决的唯一方法是遍历特定JVM实现的文档。

So the answer to your question may not be hard and fast YES/NO . 因此,对您的问题的答案可能不是一成不变的YES / NO。 Its subjective . 它的主观性

In case of server application, it is recommended use to ms and mx size as a same value. 对于服务器应用程序,建议将ms和mx size用作相同的值。 The reason is when it tried to grow the memory, it will have a burden to JVM. 原因是当它尝试增加内存时,它将给JVM造成负担。 and if heap size is same, it is easy to estimate full gc time. 如果堆大小相同,则很容易估计完整的gc时间。

In case of perm memory, after server has been warmed up. 在烫发内存的情况下,服务器已经预热。 It means most of class has been loaded so perm size is not changed usally. 这意味着大多数类都已加载,因此烫发大小通常不会更改。 So after u can measure the perm size by using gc log option, It is better to set fixed size of Perm. 因此,在使用gc log选项测量烫发尺寸后,最好设置Perm的固定尺寸。

It will be more stable in server configuration. 服务器配置将更加稳定。

In addition, if u bring more bigger size of Heap (by using -mx option). 另外,如果您带来更大的堆大小(通过使用-mx选项)。 It will takes more full gc time. 这需要更多的完整gc时间。 At the full gc time, JVM is freezing. 在完整的gc时间,JVM正在冻结。 So u need to take care of max size. 所以你需要照顾最大尺寸。

In my opinion, if u have enough memory. 在我看来,如果你有足够的记忆。 It is better to run additional JVM instance (with clustering etc) 最好运行其他JVM实例(使用群集等)

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

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