I know there are several memory types that Tomcat uses when running.
我知道Tomcat在运行时会使用几种内存类型。
The only I have ever used - java heap. It can be controlled through JAVA_OPTS env property with something like '-Xmx128M -Xms64M'
我唯一使用过的 - java堆。它可以通过JAVA_OPTS env属性控制,类似'-Xmx128M -Xms64M'
I have found that there is also -XX:MaxPermSize, -XX:MaxNewSize and etc.
我发现还有-XX:MaxPermSize,-XX:MaxNewSize等。
The reason I'm asking is that I'm trying to launch Tomcat5.5 on 200Mb RAM memory (it is VPS server). I have setup java heap size with '-Xmx128M -Xms64M', but it seems that right from startup it consumes more than that (if ever can start. Sometimes startup fails right off the bat with OutOfMemoryException), with no applications have been deployed
我问的原因是我试图在200Mb RAM内存上启动Tomcat5.5(它是VPS服务器)。我已经使用'-Xmx128M -Xms64M'设置了java堆大小,但是它似乎从启动它消耗了更多(如果有的话可以启动。有时启动失败就是使用OutOfMemoryException),没有部署任何应用程序
Noticable thing is that if I launch maven's tomcat plugin, it works just fine. Only separate tomcat fails with memory.
值得注意的是,如果我启动maven的tomcat插件,它就可以了。只有单独的tomcat会因内存而失败。
Thanks in advance for your ideas.
提前感谢您的想法。
2 个解决方案
#1
As you say, heap memory is just one of the JVM's memory pools, there are others.
正如您所说,堆内存只是JVM的内存池之一,还有其他内存池。
Read this to get an idea of what they are, how to control them, and how to monitor them:
阅读本文以了解它们是什么,如何控制它们以及如何监控它们:
http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html
Heap and Non-heap Memory
堆和非堆内存
The JVM manages two kinds of memory: heap and non-heap memory, both created when it starts.
JVM管理两种内存:堆和非堆内存,两者都在启动时创建。
Heap memory is the runtime data area from which the JVM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.
堆内存是运行时数据区,JVM从中为所有类实例和数组分配内存。堆可以是固定的或可变的大小。垃圾收集器是一个自动内存管理系统,可回收对象的堆内存。
Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the JVM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on implementation, a JVM may not garbage collect or compact it. Like the heap, the method area may be of fixed or variable size. The memory for the method area does not need to be contiguous.
非堆内存包括在JVM的内部处理或优化所需的所有线程和内存之间共享的方法区域。它存储每类结构,例如运行时常量池,字段和方法数据,以及方法和构造函数的代码。方法区域在逻辑上是堆的一部分,但是根据实现,JVM可能不会垃圾收集或压缩它。与堆一样,方法区域可以是固定的或可变的大小。方法区域的内存不需要是连续的。
In addition to the method area, a JVM implementation may require memory for internal processing or optimization which also belongs to non-heap memory. For example, the JIT compiler requires memory for storing the native machine code translated from the JVM code for high performance.
除了方法区域之外,JVM实现可能还需要用于内部处理或优化的内存,该内存也属于非堆内存。例如,JIT编译器需要用于存储从JVM代码转换的本机机器代码的内存以获得高性能。
#2
Read here for some tips on setting the java heap size. It is quite strange that Tomcat is giving you OutOfMemoryExceptions even without any applications deployed. Perhaps there is something wrong with your configuration (what OS are you using, how do you start Tomcat?).
请阅读此处以获取有关设置Java堆大小的一些提示。很明显,即使没有部署任何应用程序,Tomcat也会为您提供OutOfMemoryExceptions。也许您的配置有问题(您使用的操作系统是什么,如何启动Tomcat?)。
#1
As you say, heap memory is just one of the JVM's memory pools, there are others.
正如您所说,堆内存只是JVM的内存池之一,还有其他内存池。
Read this to get an idea of what they are, how to control them, and how to monitor them:
阅读本文以了解它们是什么,如何控制它们以及如何监控它们:
http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html
Heap and Non-heap Memory
堆和非堆内存
The JVM manages two kinds of memory: heap and non-heap memory, both created when it starts.
JVM管理两种内存:堆和非堆内存,两者都在启动时创建。
Heap memory is the runtime data area from which the JVM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.
堆内存是运行时数据区,JVM从中为所有类实例和数组分配内存。堆可以是固定的或可变的大小。垃圾收集器是一个自动内存管理系统,可回收对象的堆内存。
Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the JVM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on implementation, a JVM may not garbage collect or compact it. Like the heap, the method area may be of fixed or variable size. The memory for the method area does not need to be contiguous.
非堆内存包括在JVM的内部处理或优化所需的所有线程和内存之间共享的方法区域。它存储每类结构,例如运行时常量池,字段和方法数据,以及方法和构造函数的代码。方法区域在逻辑上是堆的一部分,但是根据实现,JVM可能不会垃圾收集或压缩它。与堆一样,方法区域可以是固定的或可变的大小。方法区域的内存不需要是连续的。
In addition to the method area, a JVM implementation may require memory for internal processing or optimization which also belongs to non-heap memory. For example, the JIT compiler requires memory for storing the native machine code translated from the JVM code for high performance.
除了方法区域之外,JVM实现可能还需要用于内部处理或优化的内存,该内存也属于非堆内存。例如,JIT编译器需要用于存储从JVM代码转换的本机机器代码的内存以获得高性能。
#2
Read here for some tips on setting the java heap size. It is quite strange that Tomcat is giving you OutOfMemoryExceptions even without any applications deployed. Perhaps there is something wrong with your configuration (what OS are you using, how do you start Tomcat?).
请阅读此处以获取有关设置Java堆大小的一些提示。很明显,即使没有部署任何应用程序,Tomcat也会为您提供OutOfMemoryExceptions。也许您的配置有问题(您使用的操作系统是什么,如何启动Tomcat?)。