如何优化Tomcatmysql 配置性能优化,提升Tomcat性能

拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(3c4dfcffa2324388-ua98).
重新安装浏览器,或使用别的浏览器如何优化tomcat配置(从内存、并发、缓存4个方面)优化 - g_blue_wind的博客 - CSDN博客
如何优化tomcat配置(从内存、并发、缓存4个方面)优化
一.Tomcat内存优化
  Tomcat内存优化主要是对 tomcat 启动参数优化,我们可以在 tomcat 的启动脚本 catalina.sh 中设置 java_OPTS 参数。&
  JAVA_OPTS参数说明&
  -server 启用jdk 的 server 版;&
  -Xms&虚拟机初始化时的最小内存;&
  -Xmx java虚拟机可使用的最大内存;&
  -XX: PermSize 内存永久保留区域&
  -XX:MaxPermSize 内存最大永久保留区域&
  服务器参数配置
  现公司服务器内存一般都可以加到最大2G ,所以可以采取以下配置:
  JAVA_OPTS=’-Xms1024m -Xmx2048m -XX: PermSize=256M -XX:MaxNewSize=256m -XX:MaxPermSize=256m’
  配置完成后可重启Tomcat ,通过以下命令进行查看配置是否生效:&
  首先查看Tomcat 进程号:
  sudo lsof -i:9027
  我们可以看到Tomcat 进程号是 12222 。&
  查看是否配置生效:
  sudo jmap – heap 12222
  我们可以看到MaxHeapSize 等参数已经生效。
二.Tomcat并发优化
  1.Tomcat连接相关参数
  在Tomcat 配置文件 server.xml 中的
   port=&9027&
  protocol=&HTTP/1.1&
  maxHttpHeaderSize=&8192&
  minProcessors=&100&
  maxProcessors=&1000&
  acceptCount=&1000&
  redirectPort=&8443&
  disableUploadTimeout=&true&/&1234567812345678
  2.调整连接器connector的并发处理能力
  1&参数说明
  maxThreads 客户请求最大线程数&
  minSpareThreads Tomcat初始化时创建的 socket 线程数&
  maxSpareThreads Tomcat连接器的最大空闲 socket 线程数&
  enableLookups 若设为true, 则支持域名解析,可把 ip 地址解析为主机名&
  redirectPort 在需要基于安全通道的场合,把客户请求转发到基于SSL 的 redirectPort 端口&
  acceptAccount 监听端口队列最大数,满了之后客户请求会被拒绝(不能小于maxSpareThreads )&
  connectionTimeout 连接超时&
  minProcessors 服务器创建时的最小处理线程数&
  maxProcessors 服务器同时最大处理线程数&
  URIEncoding URL统一编码
  2&Tomcat中的配置示例
   port=&9027&
  protocol=&HTTP/1.1&
  maxHttpHeaderSize=&8192&
  maxThreads=&1000&
  minSpareThreads=&100&
  maxSpareThreads=&1000&
  minProcessors=&100&
  maxProcessors=&1000&
  enableLookups=&false&
  URIEncoding=&utf-8&
  acceptCount=&1000&
  redirectPort=&8443&
  disableUploadTimeout=&true&/&1234567891011121312345678910111213
  3.Tomcat缓存优化
  1&参数说明
  c ompression 打开压缩功能&
  compressionMinSize 启用压缩的输出内容大小,这里面默认为2KB&
  compressableMimeType 压缩类型&
  connectionTimeout 定义建立客户连接超时的时间. 如果为 -1, 表示不限制建立客户连接的时间
  2&Tomcat中的配置示例
  &Connector port=&9027&
  protocol=&HTTP/1.1&
  maxHttpHeaderSize=&8192&
  maxThreads=&1000&
  minSpareThreads=&100&
  maxSpareThreads=&1000&
  minProcessors=&100&
  maxProcessors=&1000&
  enableLookups=&false&
  compression=&on&
  compressionMinSize=&2048&
  compressableMimeType=&text/html,text/xml,text/javascript,text/css,text/plain&
  connectionTimeout=&20000&
  URIEncoding=&utf-8&
  acceptCount=&1000&
  redirectPort=&8443&
  disableUploadTimeout=&true&/&12345678910111213141516171234567891011121314151617
  4.参考配置
  1&旧有的配置
  参考网络对服务器做过如下配置,拿出来分享下:
  &Connector port=&9027&
  protocol=&HTTP/1.1&
  maxHttpHeaderSize=&8192&
  maxThreads=&1000&
  minSpareThreads=&25&
  maxSpareThreads=&75&
  enableLookups=&false&
  compression=&on&
  compressionMinSize=&2048&
  compressableMimeType=&text/html,text/xml,text/javascript,text/css,text/plain&
  connectionTimeout=&20000&
  URIEncoding=&utf-8&
  acceptCount=&200&
  redirectPort=&8443&
  disableUploadTimeout=&true& /&123456789101112131415123456789101112131415
  后来发现在访问量达到3 百万多的时候出现性能瓶颈。&
  2&更改后的配置
  &Connector port=&9027&
  protocol=&HTTP/1.1&
  maxHttpHeaderSize=&8192&
  maxThreads=&1000&
  minSpareThreads=&100&
  maxSpareThreads=&1000&
  minProcessors=&100&
  maxProcessors=&1000&
  enableLookups=&false&
  compression=&on&
  compressionMinSize=&2048&
  compressableMimeType=&text/html,text/xml,text/javascript,text/css,text/plain&
  connectionTimeout=&20000&
  URIEncoding=&utf-8&
  acceptCount=&1000&
  redirectPort=&8443&
  disableUploadTimeout=&true&/&
我的热门文章博客分类:
这是个很简单的问题,但是搜了一圈,发现大家都写错了。所以这里总结一下:
几乎所有的中文网页都介绍,要修改Tomcat的默认最大并发连接数,应该进行如下设置(实际上这些步骤是错误的):
--------------------------------------------
在tomcat配置文件server.xml中的&Connector ... /&配置中,和连接数相关的参数有:  minProcessors:最小空闲连接线程数,用于提高系统处理性能,默认值为10maxProcessors:最大连接线程数,即:并发处理的最大请求数,默认值为75acceptCount:允许的最大连接数,应大于等于maxProcessors,默认值为100enableLookups:是否反查域名,取值为:true或false。为了提高处理能力,应设置为falseconnectionTimeout:网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。其中和最大连接数相关的参数为maxProcessors和acceptCount。如果要加大并发连接数,应同时加大这两个参数。web server允许的最大连接数还受制于操作系统的内核参数设置,通常Windows是2000个左右,Linux是1000个左右。Unix中如何设置这些参数,请参阅Unix常用监控和管理命令具体的配置信息:Java代码
&Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8080"
minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="20000 " useURIValidationHack="false"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/&
--------------------------------------------
但是我仔细查了一圈,发现这个说法只是以讹传讹,并不适用于Tomcat 5.5以上的版本。这里先教大家怎么去查Tomcat的官网:
首先,在这里: 我们点击左侧导航栏中“Documentation”下的Tomcat 7.0,进入到这个链接中: ,详细的信息我们不用都看,在左侧导航栏中有一个链接,我们点进去之后,再点击其左侧导航栏中connector一项的,就进入到HTTP连接数及其他相关属性的设置页面了。在这里()我们可以看到,在Connector的属性配置中,压根就没有maxProcessors等的设置选项。其中这句话已经介绍得很清楚:
If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount attribute).
所以我们需要设置的是maxThreads和acceptCount这两个值:
其中,maxThreads的介绍如下:
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. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.
而acceptCount的介绍为:
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 will be refused. The default value is 100.
所以两者的默认值分别是200和100,要调整Tomcat的默认最大连接数,可以增加这两个属性的值,并且使acceptCount大于等于maxThreads:
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" acceptCount="500" maxThreads="400"
&Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" acceptCount="500" maxThreads="400" /&
今天就记录这么多,希望大家以后在转载别人的经验时更用心些,不要老出现上面那些以讹传讹的情况。也希望能对有些朋友起到帮助。
浏览 43254
zhangzhaoaaa
浏览: 815430 次
来自: 北京
很多API doc生成工具生成doc需要重度依赖代码里加注解的 ...
留言止于智者
应该是@Before public void setUp(){ ...
2楼理解很透呀,我用程序测了,是正确的。
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'}

我要回帖

更多关于 如何优化显卡性能 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信