Tomcat参数设置,解决内存溢出问题
Tomcat默认参数不适合生产环境使用,因此需要修改一些参数
1、修改启动时内存参数、并指定JVM时区 (在Windows Server 2008 下时间少了8个小时):
在Tomcat上运行j2ee项目代码时,经常会出现内存溢出的情况,解决办法是在系统参数中增加系统参数:
Windows下, 在catalina.bat最前面:
set JAVA_OPTS=-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m;-Duser.timezone=GMT+08;
一定加在catalina.bat最前面。
Linux下,在catalina.sh最前面增加:
JAVA_OPTS="-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m -Duser.timezone=Asia/Shanghai"
注意:前后二者区别,有无set,有无双引号。
2、线程池配置(Tomcat6下)
使用线程池,用较少的线程处理较多的访问,可以提高tomcat处理请求的能力。使用方式:
首先。打开/conf/server.xml,增加
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="500" minSpareThreads="20" maxIdleTime="60000" />
最大线程500(一般服务器足以),最小空闲线程数20,线程最大空闲时间60秒。
然后,修改<Connector ...>节点,增加executor属性,如:
<Connector executor="tomcatThreadPool"
port="80"
protocol="HTTP/1.1"
maxThreads="600"
minSpareThreads="100"
maxSpareThreads="300"
connectionTimeout="60000"
keepAliveTimeout="15000"
maxKeepAliveRequests="1"
redirectPort="443"
....../>
maxThreads:Tomcat可创建的最大的线程数,每一个线程处理一个请求;
minSpareThreads:最小备用线程数,tomcat启动时的初始化的线程数;
maxSpareThreads:最大备用线程数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程;
acceptCount:指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,就是被排队的请求数,超过这个数的请求将拒绝连接。
connnectionTimeout:网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
enableLookups:是否允许DNS查询
注意:可以多个connector公用1个线程池。
3、调整连接相关Connector的参数:
<Connector executor="tomcatThreadPool"
port="80" protocol="HTTP/1.1"
connectionTimeout="60000"
keepAliveTimeout="15000"
maxKeepAliveRequests="1"
redirectPort="443"
maxHttpHeaderSize="8192" URIEncoding="UTF-8" enableLookups="false" acceptCount="100" disableUploadTimeout="true"/>
参数说明:
- connectionTimeout - 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
- keepAliveTimeout - 长连接最大保持时间(毫秒)。此处为15秒。
- maxKeepAliveRequests - 最大长连接个数(1表示禁用,-1表示不限制个数,默认100个。一般设置在100~200之间) the maximum number of HTTP requests that can be held in the pipeline until the connection is closed by the server. Setting this attribute to 1 disables HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 allows an unlimited number of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.
- maxHttpHeaderSize - http请求头信息的最大程度,超过此长度的部分不予处理。一般8K。
- URIEncoding - 指定Tomcat容器的URL编码格式。
- acceptCount - 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理,默认为10个。defines the maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full are refused. The default value is 10.
- disableUploadTimeout - 上传时是否使用超时机制
- enableLookups - 是否反查域名,取值为:true或false。为了提高处理能力,应设置为false
- bufferSize - defines the size (in bytes) of the buffer to be provided for input streams created by this connector. By default, buffers of 2048 bytes are provided.
- maxSpareThreads - 做多空闲连接数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程 the maximum number of unused request processing threads that are allowed to exist until the thread pool starts stopping the unnecessary threads. The default value is 50.
- maxThreads - 最多同时处理的连接数,Tomcat使用线程来处理接收的每个请求。这个值表示Tomcat可创建的最大的线程数。。 the maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.
- minSpareThreads - 最小空闲线程数,Tomcat初始化时创建的线程数 the number of request processing threads that are created when this Connector is first started. The connector will also make sure it has the specified number of idle processing threads available. This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.
- minProcessors - 最小空闲连接线程数,用于提高系统处理性能,默认值为10。(用于Tomcat4中)
- maxProcessors - 最大连接线程数,即:并发处理的最大请求数,默认值为75。(用于Tomcat4中)
备注:
Tomcat4中可以通过修改minProcessors和maxProcessors的值来控制线程数。
在Tomcat5+主要对以下参数调整
maxThreads
Tomcat使用线程来处理接收的每个请求。这个值表示Tomcat可创建的最大的线程数。
acceptCount
指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理。
connnectionTimeout
网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
minSpareThreads
Tomcat初始化时创建的线程数。
maxSpareThreads
一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程。
4、负载均衡、集群的配置
Tomcat6支持分布式部署,可以实现集群功能,提高响应能力。
5、
利用JMX监控Tomcat运行情况,需要手工调整启动参数,如下:
打开cataline.bat,增加一行
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=10090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
linux下修改cataline.sh:
JAVA_OPTS="-Dcom.sun.management.jmxremote.port=10090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=%CATALINA_BASE\conf\logging.properties"
注意JDK\jre\lib\management\management.properties文件必须存在。
重新启动tomcat节点,然后用jconsole连接(此处端口wei10090)
6、Tomcat增加一个应用
在server.xml的Host标签中增加行
<Context displayName="OA" docBase="/app/web-apps/GACWP" path="" />
Tomcat参数设置,解决内存溢出问题的更多相关文章
- solrCloud设置Tomcat jvm内存解决内存溢出的问题
几乎已经搜遍了整个网络,没有找到一篇解决设置solr在Tomcat下设置虚拟机内存的文章. 因为之前一直是在Tomcat中设置zkhost参数,在加上jvm参数后会无法启动,添加其他参数也没有生效 ...
- android解决内存溢出的问题(没有从根本上解决)
Android游戏虚拟机算法JNI 尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完 ...
- Linux swappiness参数设置与内存交换
swappiness参数设置与内存交换 by:授客 QQ:1033553122 简介 swappiness,Linux内核参数,控制换出运行时内存的相对权重.swappiness参数值可设置范围在0到 ...
- tomcat内存修改 解决内存溢出异常
有时候tomcat刚解压完,部署项目后运行会报内存溢出的错误. 原因:项目过大,tomcat内存小. 解决:找到[tomcat]/bin/catlina.bat文件,打开: 在@echo off上面( ...
- Eclipse设置虚拟机参数 (转 构建内存溢出)
Java -verbose:gc 中参数-verbose:gc 表示输出虚拟机中GC的详细情况. 首先在Eclipse的Debug页签中设置虚拟机参数: 步骤: 1.选中已经写好的项目 2.Run-& ...
- Tomcat启动项目时内存溢出问题如何解决
在Eclipse中,内存溢出(报不能创建JAVA虚拟机错时,也可能是这里配错了.) 1.双击Tomcat,点击Open launch configuration,Arguments, 2.在VM ar ...
- tomcat启动时,内存溢出,Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
问题原因 通过tomcat启动项目,也许是因为项目太大,配置的内存不够用了.老是报内存溢出的问题. 解决办法 1.选中项目 右键 run as ->Run Configurations... ...
- 运行两个以上tomcat的设置及内存设置
运行两个或以上tomcat的设置方法 1.解决端口冲突问题设置方法很简单,修改conf/server.xml配置文件中的3个端口即可.默认端口:8005.8080.8009.一般情况位置如下:**** ...
- java虚拟内存设置 防止内存溢出 OutOfMemory【转】【原】
outofmemory permgen 这个问题主要还是由 java.lang.OutOfMemoryError: Java heap space 引起的. 有这两种解决方法: 1.设置环境变量 解决 ...
随机推荐
- 从入门到深入FIDDLER 2
在开发的过程中使用过不少的HTTP网络抓包工具,如:HTTPAnalyzer,HttpWatch. Fiddler几乎囊括了大部分的抓包请求,当然最给力的还是它的断点调试功能,尤其还有使用本地文件代替 ...
- YII框架增删改查常用语句
//实例化db $db = new \yii\db\Query(); //插入 $db->createCommand()->insert('user', [ 'name' => 't ...
- 解析eBay BASE模式、去哪儿及蘑菇街分布式架构
目录:问题分析概念解读Most Simple原理解读eBey.去哪儿.蘑菇街分布式事务案例分析 参考资料 1.问题解析 要想做架构,必须识别出问题,即是谁的问题,什么问题.明显的,分布式架构解决 ...
- html-定位
概述: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- selenium设置chrome和phantomjs的请求头信息
selenium设置chrome和phantomjs的请求头信息 出于反爬虫也好-跳转到手机端页面也好都需要设置请求头,那么如何进行呢? 目录 一:selenium设置phantomjs请求头: ...
- C. A Mist of Florescence ----- Codeforces Round #487 (Div. 2)
C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Python import错误
今天将一个文件命名为select,在其中import了 A文件 再然后发现 B文件import A文件,会将select也一起运行. 还出现的问题是 A中的类实例的时候说找不到. 最后想到selec ...
- js函数和变量的声明与执行顺序
一.函数执行顺序 1.正常顺序 function f(){ alert(2); } f(); //alert 2 所有浏览器都能测试通过. 2.倒序调用 f(); //alert 2 function ...
- 学习Nodejs:《Node.js开发指南》微博项目express2迁移至express4过程中填的坑
<Node.js开发指南>项目地址https://github.com/BYVoid/microblog好不容易找到的基础版教程,但书中是基于express2的,而现在用的是express ...
- c#窗体form的美化