Springboot - 2.2.6 内嵌tomcat配置修改及后台日志报错信息

    前面想着升级一下springboot2.2.6 ,下午做一个小试验打了一点压力到springboot服务,发现报了异常:

        More than the maximum allowed number of headers, [100]

        java.lang.IllegalArgumentException: Request header is too large

        java.lang.OutOfMemoryError: Requested array size exceeds VM limit

    超过允许的最大值【100】?【too large】?【VM limit】?,整几个异常以前也见过,没有太在意,但是压力稍微一上去,就会出现这个异常并且服务就会卡住不接受任何数据,查查源码看看。。。 

java.lang.IllegalStateException: More than the maximum allowed number of headers, [100], were detected.
        at org.apache.tomcat.util.http.MimeHeaders.createHeader(MimeHeaders.java:260) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.tomcat.util.http.MimeHeaders.addValue(MimeHeaders.java:304) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.Http11InputBuffer.parseHeader(Http11InputBuffer.java:833) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.Http11InputBuffer.parseHeaders(Http11InputBuffer.java:584) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:283) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_242]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_242]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_242]

    org.apache.coyote.AbstractProtocol.java中;默认值是100呀,怪不得一直打不上去,知道原因就好办了;

private int maxHeaderCount = 100;
    public int getMaxHeaderCount() {
        return maxHeaderCount;
    }
    public void setMaxHeaderCount(int maxHeaderCount) {
        this.maxHeaderCount = maxHeaderCount;
    }

     可以在项目中增加一个类:

package daopinz.sample;

import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author daopinz
 * @Date 2020/5/11 13:59
 */
@Configuration
public class TomcatCustomizer {

    @Bean
    public ConfigurableServletWebServerFactory configurableServletWebServerFactory(){
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.setProtocol("org.apache.coyote.http11.Http11NioProtocol");
        factory.setPort(8850);
        factory.addConnectorCustomizers( connector -> {
            Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
            protocol.setDisableUploadTimeout(false);
            //protocol.setAcceptCount(200);
            //protocol.setMaxConnections(200);
            protocol.setMaxHeaderCount(20000);
            protocol.setConnectionTimeout(20000);
            protocol.setMaxHttpHeaderSize(209715200);
            protocol.setMaxSavePostSize(4194304);
        } );
        return factory;
    }
}

    同时在配置文件中修改配置(application.yml):

server:
    port: 8850
    max-http-header-size: 209715200
    tomcat:
        accept-count: 200
        max-connections: 200
        max-http-post-size: 200
        max-http-header-size: 209715200

    这样修改之后,重新打包并重启服务,就会发现可以接收的数据量让你惊讶,原来这里修改后,可以承受好大的数据啊!!!

下面的两个异常,也会乖乖的 '缴械投降' 啦!

java.lang.IllegalArgumentException: Request header is too large
        at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:741) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.Http11InputBuffer.parseHeader(Http11InputBuffer.java:824) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.Http11InputBuffer.parseHeaders(Http11InputBuffer.java:584) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:283) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_242]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_242]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_242]

 

2020-05-11 07:02:14.987 ERROR 1 --- [nio-8850-exec-2] o.a.coyote.http11.Http11NioProtocol      : Failed to complete processing of a request

java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57) ~[na:1.8.0_242]
        at java.nio.ByteBuffer.allocate(ByteBuffer.java:335) ~[na:1.8.0_242]
        at org.apache.coyote.http11.Http11OutputBuffer.<init>(Http11OutputBuffer.java:107) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.Http11Processor.<init>(Http11Processor.java:162) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.http11.AbstractHttp11Protocol.createProcessor(AbstractHttp11Protocol.java:990) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_242]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_242]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.33.jar!/:9.0.33]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_242]

2020-05-11 07:02:15.043 ERROR 1 --- [nio-8850-exec-3] o.a.coyote.http11.Http11NioProtocol      : Failed to complete processing of a request

java.lang.OutOfMemoryError: Requested array size exceeds VM limit

2020-05-11 07:02:20.047 ERROR 1 --- [nio-8850-exec-4] o.a.coyote.http11.Http11NioProtocol      : Failed to complete processing of a request

java.lang.OutOfMemoryError: Requested array size exceeds VM limit

2020-05-11 07:02:35.052 ERROR 1 --- [nio-8850-exec-5] o.a.coyote.http11.Http11NioProtocol      : Failed to complete processing of a request

java.lang.OutOfMemoryError: Requested array size exceeds VM limit

2020-05-11 07:02:35.113 ERROR 1 --- [nio-8850-exec-6] o.a.coyote.http11.Http11NioProtocol      : Failed to complete processing of a request

java.lang.OutOfMemoryError: Requested array size exceeds VM limit

    最后还是想贴一下改完之后,服务端平均一秒内处理了多少条数据。。。(●ˇ∀ˇ●),1700/s ! ! ! 

2020-05-11 07:10:00.033 [nio-8850-exec-7] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.088 [nio-8850-exec-8] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.142 [nio-8850-exec-9] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.196 [io-8850-exec-10] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.249 [nio-8850-exec-1] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.304 [nio-8850-exec-2] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.364 [nio-8850-exec-3] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.421 [nio-8850-exec-4] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.514 [nio-8850-exec-5] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.584 [nio-8850-exec-6] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.653 [nio-8850-exec-7] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.706 [nio-8850-exec-8] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.763 [nio-8850-exec-9] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.817 [io-8850-exec-10] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.880 [nio-8850-exec-1] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.933 [nio-8850-exec-2] daopinz.sample.CallbackController: payload about has: 100
2020-05-11 07:10:00.990 [nio-8850-exec-3] daopinz.sample.CallbackController: payload about has: 100

 

posted @ 2022-01-27 18:35  zhangdaopin  阅读(1558)  评论(0编辑  收藏  举报