About solving the downtime caused by the Tomcat server Connection reset by peer

org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:407)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer (ByteChunk.java: 480 )
    at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
    at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:432)
    at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:420)
    at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
    at com.dtxxsoft.spm.sys.controller.SpmUploadFileController.download(SpmUploadFileController.java:299)
    at sun.reflect.GeneratedMethodAccessor1477.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.chinasofti.ro.bizframework.core.utils.ActionInvokerUtil.invoke(ActionInvokerUtil.java:207)
    at com.chinasofti.ro.bizframework.core.mvc.ActionInvoker.invoke(ActionInvoker.java:181)
    at com.chinasofti.ro.bizframework.core.mvc.ActionFilter.doFilter(ActionFilter.java:179)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.chinasofti.ro.bizframework.core.web.filter.DisableUrlSessionFilter.doFilter(DisableUrlSessionFilter.java:59)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.chinasofti.ro.bizframework.core.web.filter.LocaleFilter.doFilterInternal(LocaleFilter.java:65)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.dtxxsoft.spm.sys.filter.SSOFilter.doFilter (SSOFilter.java: 162 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.chinasofti.ro.bizframework.core.web.filter.InitialFilter.doFilter(InitialFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at com.googlecode.psiprobe.Tomcat70AgentValve.invoke(Tomcat70AgentValve.java:38)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1749)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1708)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Connection reset by peer
    at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
    at sun.nio.ch.IOUtil.write(IOUtil.java:65)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
    at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:125)
    at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:101)
    at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:174)
    at org.apache.coyote.http11.InternalNioOutputBuffer.writeToSocket(InternalNioOutputBuffer.java:163)
    at org.apache.coyote.http11.InternalNioOutputBuffer.flushBuffer(InternalNioOutputBuffer.java:242)
    at org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:213)
    at org.apache.coyote.http11.InternalNioOutputBuffer.access$000(InternalNioOutputBuffer.java:41)
    at org.apache.coyote.http11.InternalNioOutputBuffer$SocketOutputBuffer.doWrite(InternalNioOutputBuffer.java:268)
    at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:119)
    at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
    at org.apache.coyote.Response.doWrite(Response.java:499)
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:402)
    ... 48 more

First, the server error message was posted, mainly because the requests processed by the server at the same time exceeded the limit, resulting in downtime. Summarize two directions to solve the problem.

  1. Modify the connection timeout time connectionTimeout
  2. Modify the maximum number of threads and the maximum number of queues maxThreads, acceptCount

  The modified files are all Tomcat-"conf-"server.xml 

  

 

  

The last two parameters have the following meanings:

maxThreads: The maximum number of threads started by tomcat, that is, the number of tasks processed at the same time, the default value is 200

acceptCount: When the number of threads started by tomcat reaches the maximum, the number of queued requests accepted, the default value is 100

 

How these two values ​​work, please see the following three cases

Case 1: Accepting a request, at this time, the number of threads started by tomcat does not reach maxThreads, and tomcat will start a thread to process the request.

Case 2: Accept a request. At this time, the number of threads started by tomcat has reached maxThreads, and tomcat will put the request into the waiting queue and wait for idle threads.

Case 3: Accepting a request, the number of threads started by tomcat has reached maxThreads, and the number of requests in the waiting queue has also reached acceptCount. At this time, tomcat will directly reject the request and return connection refused

How to configure maxThreads

General server operations include volume: 1 calculation (mainly consuming cpu), 2 waiting (io, database, etc.)

In the first extreme case, if our operation is purely computing, then the main limitation of the system response time is the computing power of the cpu. At this time, maxThreads should be set as small as possible to reduce the number of threads competing for the cpu at the same time. Improve computing efficiency and improve the overall processing power of the system.

In the second extreme case, if our operation is purely IO or database, then the main limitation of response time becomes waiting for external resources. At this time, maxThreads should be set as large as possible, so as to increase the number of simultaneous requests, thereby improving The overall processing power of the system. In this case, because the amount of requests processed by tomcat at the same time will be relatively large, you need to pay attention to the virtual machine memory settings of tomcat and the open file limit of linux.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325790714&siteId=291194637