max-http-header-size設置 server.max-http-header-size=999999999 //953m JVM參數配置 -Xms800m -Xmx800m 寫一個rest api @RestController("action") public class HttpH ...
max-http-header-size設置
server.max-http-header-size=999999999 //953m
JVM參數配置
-Xms800m -Xmx800m
寫一個rest api
@RestController("action") public class HttpHandler { @PostMapping("/get") public String get() { return "get"; } }
post訪問
服務端OOM
java.lang.OutOfMemoryError: Java heap space at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57) ~[na:1.8.0_152] at java.nio.ByteBuffer.allocate(ByteBuffer.java:335) ~[na:1.8.0_152] 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_152] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_152] 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_152]
debug,分析
而jvm堆的最大大小是800m,第一時間就oom
其實http11InputBuffer也要初始化一個buffer,這個同樣要占很多記憶體。
為了演示,本文例子比較極端,堆的大小直接小於buffer的大小,一次請求就oom,一般情況下就算堆的大小大於buffer的大小,如果這個max-size設置的不合理過大,隨著請求併發的上升,buffer也會占用大量記憶體,從而導致oom。
max-size設置過小
異常Request header is too large,導致post的header存不下來,要根據實際情況進行設置這個值。