tomcat内存优化设置

服务器运行一段时间就会崩溃,查看日志发现崩溃前抛出的是内存不够的异常,部署的时候没有对内存进行优化设置,采用的是默认设置,服务器配置高,不用也是浪费,于是查了些与内存设置有关的文档,在这里把与内存优化相关的做下记录。
出现out of memory可能的原因(摘自tomcat wiki)
1.You're out of memory. Simple as that - add more to your heap.
2.You're out of memory. You have code which is hanging onto object references and the garbage collector can't do its job. Get a profiler to debug this one.
3.You ran out of file descriptors. If you are on a *nix system, it has been observed that an OutOfMemoryError can be thrown if you run out of file descriptors. This can occur if your threshold is too low. The ulimit program can help you out here. You also may need to account for socket connections too when thinking about these thresholds. Google is your friend for getting more information about this topic.
4.You have too many threads running. Some OS's have a limit to the number of threads which may be executed by a single process. (Which is what the JVM is.) Refer to your OS docs for more information on how to raise this threshold.
5.If you have a lot of servlets or JSP's, you may need to increase your permanent generation. By default, it is 64MB. Quadrupling it to be -XX:MaxPermSize=256m might be a good start.
6.Your OS limits the amount of memory your process may take. OK, this one is grasping at straws.
7.The JVM has a bug. This has been known to happen with JVM1.2.? and using EJB's with another servlet engine.
8.Not actually a reason - but on your particular platform, look at the java -X options. They may be VERY helpful.
9.Your classloaders are not being garbage collected.
10.You run out of process memory (non java/GC memory), for example when using java.util.zip classes or JNI classes allocating process memory. See Instantiating Inflater/Deflater causes OutOfMemoryError; finalizers not called promptly enough
翻译过来的意思是:
1.用完了内存
2.代码有内存泄露的bug
3.用完了文件描述符。linux系统中文件数量限制有两个方面:硬盘空间和文件描述符数量。具体详情请google。
4.有太多线程在运行。有些操作系统会限制线程数量。
5.有太多的servlet或JSP,这占用了大量的permanent generation。
6.操作系统限制了进程可以使用的内存大小。
7.JVM有bug。目前已知JM1.2有bug。
8.不明原因。建议打开java -X选项查看原因。
9.类加载器没有被gc回收。
10。程序用完了内存(不是java内存)比如用native方法申请了很多的内存。
分析了程序大概的原因是第一条,用完了JVM申请的内存,于是查找tomcat的JVM内存分配优化。具体做法:
修改CATALINA_HOME/bin/catalina.sh文件,在开头加上JAVA_OPTS='-Xms8192m -Xmx8192m -XX:MaxPermSize=512m'

猜你喜欢

转载自lwjlaser.iteye.com/blog/1534267