Tomcat修改JVM内存配置
2012-04-12 16:57
429 查看
1、修改启动时内存参数、并指定JVM时区(在windows server 2008 下时间少了8个小时):
在Tomcat上运行j2ee项目代码时,经常会出现内存溢出的情况,解决办法是在系统参数中增加系统参数:
window下, 在catalina.bat最前面:
查看源代码打印帮助1 set JAVA_OPTS=-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m
一定加在catalina.bat最前面。
linux下,在catalina.sh最前面增加:
查看源代码打印帮助1 JAVA_OPTS="-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m -Duser.timezone=Asia/Shanghai"
注意:前后二者区别,有无set,有无双引号。
2、线程池配置(Tomcat6下)
使用线程池,用较少的线程处理较多的访问,可以提高tomcat处理请求的能力。使用方式:
首先。打开/conf/server.xml,增加
查看源代码打印帮助1 <executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="500" minSpareThreads="20" maxIdleTime="60000" />
最大线程500(一般服务器足以),最小空闲线程数20,线程最大空闲时间60 秒。
然后,修改节点,增加executor属性,如:
查看源代码打印帮助1 <connector executor="tomcatThreadPool"
2 port="80" protocol="HTTP/1.1"
3 connectionTimeout="60000"
4 keepAliveTimeout="15000"
5 maxKeepAliveRequests="1"
6 redirectPort="443"
7 ....../>
注意:可以多个connector公用1个线程池。
3、调整连接相关Connector的参数:
查看源代码打印帮助01 <connector executor="tomcatThreadPool"
02 port="80" protocol="HTTP/1.1"
03 connectionTimeout="60000"
04 keepAliveTimeout="15000"
05 maxKeepAliveRequests="1"
06 redirectPort="443"
07 maxHttpHeaderSize="8192" URIEncoding="UTF-8" enableLookups="false" acceptCount="100" disableUploadTimeout="true"/>
08
09 参数说明:
10 * connectionTimeout - 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
11 * keepAliveTimeout - 长连接最大保持时间(毫秒)。此处为15秒。
12 * 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.
13 * maxHttpHeaderSize - http请求头信息的最大程度,超过此长度的部分不予处理。一般8K。
14 * URIEncoding - 指定Tomcat容器的URL编码格式。
15 * 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.
16 * disableUploadTimeout - 上传时是否使用超时机制
17 * enableLookups - 是否反查域名,取值为:true或false。为了提高处理能力,应设置为false
18 * 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.
19 * 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.
20 * 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.
21 * 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.
22 * minProcessors - 最小空闲连接线程数,用于提高系统处理性能,默认值为10。(用于Tomcat4中)
23 * 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,增加一行
查看源代码打印帮助1 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:
查看源代码打印帮助1 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标签中增加行
查看源代码打印帮助1 <context displayName="OA" docBase="/app/web-apps/GACWP" path="" />
path代表上下文名称,空表示是根路径。
在Tomcat上运行j2ee项目代码时,经常会出现内存溢出的情况,解决办法是在系统参数中增加系统参数:
window下, 在catalina.bat最前面:
查看源代码打印帮助1 set JAVA_OPTS=-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m
一定加在catalina.bat最前面。
linux下,在catalina.sh最前面增加:
查看源代码打印帮助1 JAVA_OPTS="-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m -Duser.timezone=Asia/Shanghai"
注意:前后二者区别,有无set,有无双引号。
2、线程池配置(Tomcat6下)
使用线程池,用较少的线程处理较多的访问,可以提高tomcat处理请求的能力。使用方式:
首先。打开/conf/server.xml,增加
查看源代码打印帮助1 <executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="500" minSpareThreads="20" maxIdleTime="60000" />
最大线程500(一般服务器足以),最小空闲线程数20,线程最大空闲时间60 秒。
然后,修改节点,增加executor属性,如:
查看源代码打印帮助1 <connector executor="tomcatThreadPool"
2 port="80" protocol="HTTP/1.1"
3 connectionTimeout="60000"
4 keepAliveTimeout="15000"
5 maxKeepAliveRequests="1"
6 redirectPort="443"
7 ....../>
注意:可以多个connector公用1个线程池。
3、调整连接相关Connector的参数:
查看源代码打印帮助01 <connector executor="tomcatThreadPool"
02 port="80" protocol="HTTP/1.1"
03 connectionTimeout="60000"
04 keepAliveTimeout="15000"
05 maxKeepAliveRequests="1"
06 redirectPort="443"
07 maxHttpHeaderSize="8192" URIEncoding="UTF-8" enableLookups="false" acceptCount="100" disableUploadTimeout="true"/>
08
09 参数说明:
10 * connectionTimeout - 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
11 * keepAliveTimeout - 长连接最大保持时间(毫秒)。此处为15秒。
12 * 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.
13 * maxHttpHeaderSize - http请求头信息的最大程度,超过此长度的部分不予处理。一般8K。
14 * URIEncoding - 指定Tomcat容器的URL编码格式。
15 * 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.
16 * disableUploadTimeout - 上传时是否使用超时机制
17 * enableLookups - 是否反查域名,取值为:true或false。为了提高处理能力,应设置为false
18 * 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.
19 * 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.
20 * 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.
21 * 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.
22 * minProcessors - 最小空闲连接线程数,用于提高系统处理性能,默认值为10。(用于Tomcat4中)
23 * 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,增加一行
查看源代码打印帮助1 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:
查看源代码打印帮助1 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标签中增加行
查看源代码打印帮助1 <context displayName="OA" docBase="/app/web-apps/GACWP" path="" />
path代表上下文名称,空表示是根路径。
相关文章推荐
- Tomcat中JVM内存溢出及合理配置
- 远程调试配置 修改tomcat内存
- Linux 下修改Tomcat使用的JVM内存大小
- Linux下tomcat JVM内存 配置
- Linux下tomcat JVM内存 配置 原创 2016年03月06日 15:10:11 4249 常见的内存溢出有以下两种: java.lang.OutOfMemoryError: PermGen
- tomcat JVM内存 配置
- MyEclipse设置Jvm内存大小(即设置tomcat的内存配置大小)
- Linux下tomcat JVM内存 配置
- Tomcat中JVM内存溢出及合理配置
- 关于jvm内存分配的问题heap size [268435456] not equal to maximum heap size [2147483648],需要修改的jvm配置
- Linux下Tomcat占用JVM内存数修改及监控
- JBOSS以及tomcat最大连接数配置和jvm内存配置
- Linux下tomcat JVM内存 配置
- Tomcat中JVM内存溢出及合理配置
- Linux和windows下内存溢出以及修改tomcat的jvm内存
- 【转】Linux 下修改Tomcat使用的JVM内存大小
- tomcat7 内存配置修改方法
- Tomcat中JVM内存溢出及合理配置
- Tomcat中JVM内存溢出及合理配置
- Linux下tomcat JVM内存 配置