tomcat生产集群环境性能问题


   最近生产上进群环境出现系统访问缓慢,甚至出现网络连接超时现象。


问题起因汇总:1,服务器所在物理主机出现ioerror ,后来和云平台同事那边了解到是云主机出现设备故障引起的文件系统损坏。

                         2,每个集群节点tomcat 并发连接优化,如下:


                           tomcat的maxThreads、acceptCount(最大线程数、最大排队数)   

                                    从官方文档看出:
                             
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.


maxThreads

The maximum number of request processing threads to be created by thisConnector, 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.


  maxthreads 这个参数配置了tomcat能够开启处理每个http请求的最大线程数,tomcat针对每一个http请求都会开启一个线程去处理。也就是支持的连接并发数。

   acceptcount 这个参数配置的是请求等待队列大小,也就是说一个请求过来,如果能够进入这个队列,那么客户端可以处于等待状态,否则队列满了的时候,就会直接被tomcat refuse掉。


综上,这两个参数配置恰当对系统吞吐量影响较大。


                    3,代码优化
                          优化代码时候,经过排查代码发现,在数据接口层有个方法使用 synchronized 关键字,这是个同步等待标志,所有的线程需要竞争这个资源,等拿到锁后才可以进入执行,这样就导致了,并发环境下多线程等待资源的情况,从而导致系统请求连接不能及时断开,形成长连接,直接导致tomcat的启动的处理连接线程数达到配置的最高值。 从而在负债均衡那边出现心跳检查tomcat的时候出现被拒绝现象。恶性循环,直接导致,系统无比缓慢。
                      去掉synchronized关键字后,系统明显变快。

                 综上所描述,这次系统优化成功。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值