龙之队|一次线上JVM内存溢出分析,GC分析、MAT、gcviewer( 三 )

可以看到我同时配置了maxHttpPostSize和maxHttpHeaderSize为10MB大小 , 而且我还配置了500个最大线程 , 满载时就单单Buffer就要耗费4G的内存 。
后面我优化成:application.yml
server:port: 80servlet:context-path: /tomcat:maxThreads: 400minSpareThreads: 50看了源码才发现maxHttpHeaderSize默认配置了8k , maxHttpPostSize默认配置2M,默认情况下是够用了 , 除非你再header上携带大量的信息 。
maxHttpHeaderSize设置源码SpringBoot是通过org.springframework.boot.autoconfigure.web.ServerProperties配置
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)public class ServerProperties {?/*** Server HTTP port.*/private Integer port;?/*** Network address to which the server should bind.*/private InetAddress address;?@NestedConfigurationPropertyprivate final ErrorProperties error = new ErrorProperties();?/*** Whether X-Forwarded-* headers should be applied to the HttpRequest.*/private Boolean useForwardHeaders;?/*** Value to use for the Server response header (if empty, no header is sent).*/private String serverHeader;?/*** Maximum size of the HTTP message header.*/private DataSize maxHttpHeaderSize = DataSize.ofKilobytes(8);?/*** Time that connectors wait for another HTTP request before closing the connection.* When not set, the connector's container-specific default is used. Use a value of -1* to indicate no (that is, an infinite) timeout.*/private Duration connectionTimeout;?@NestedConfigurationPropertyprivate Ssl ssl;?@NestedConfigurationPropertyprivate final Compression compression = new Compression();?@NestedConfigurationPropertyprivate final Http2 http2 = new Http2();?private final Servlet servlet = new Servlet();?private final Tomcat tomcat = new Tomcat();?private final Jetty jetty = new Jetty();?private final Undertow undertow = new Undertow();...public static class Tomcat {.../*** Maximum size of the HTTP message header.*/private DataSize maxHttpHeaderSize = DataSize.ofBytes(0);@Deprecated@DeprecatedConfigurationProperty(replacement = "server.max-http-header-size")public DataSize getMaxHttpHeaderSize() {return this.maxHttpHeaderSize;}?@Deprecatedpublic void setMaxHttpHeaderSize(DataSize maxHttpHeaderSize) {this.maxHttpHeaderSize = maxHttpHeaderSize;}...}}?查看一下哪里调用getMaxHttpHeaderSize()方法
org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer
龙之队|一次线上JVM内存溢出分析,GC分析、MAT、gcviewer
龙之队|一次线上JVM内存溢出分析,GC分析、MAT、gcviewerorg.apache.coyote.http11.AbstractHttp11Protocol是一个抽象类 , 我们使用的是NIO , 则它的子类是org.apache.coyote.http11.Http11AprProtocol
在org.apache.coyote.http11.AbstractHttp11Protocol中maxHttpHeaderSize是如何被调用
龙之队|一次线上JVM内存溢出分析,GC分析、MAT、gcviewer


推荐阅读