java 如何通过配置设置Tomcat响应缓冲区大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7271186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:22:19  来源:igfitidea点击:

How do I set Tomcat response buffer size through configuration?

javatomcat

提问by Bruno Bossola

I want to change through configuration (afaik server.xml) the default response buffer size. The documentation states that this is possible using the "bufferSize" attribute inside the "Connector" element but this is not working. I also tried to change "socket.appWriteBufSize" and "socket.appReadBufSize" but no luck:

我想通过配置(afaik server.xml)更改默认响应缓冲区大小。文档指出,使用“Connector”元素内的“bufferSize”属性是可能的,但这不起作用。我还尝试更改“socket.appWriteBufSize”和“socket.appReadBufSize”,但没有成功:

<Connector port="8080" protocol="HTTP/1.1" 
            connectionTimeout="20000"
    bufferSize="64000" 
    maxHttpHeaderSize="64000"
    socket.appWriteBufSize="64000"
    socket.appReadBufSize="64000"
    redirectPort="8443" />

Note that if I change the response size from my java code (httpResponse.setBufferSize(64000)) it will work, but for good reason I want to use the standard tomcat configuration mechanism.

请注意,如果我从我的 java 代码 (httpResponse.setBufferSize(64000)) 更改响应大小,它将起作用,但有充分的理由我想使用标准的 tomcat 配置机制。

All tests were done using a freshly downloaded Tomcat.

所有测试均使用新下载的 Tomcat 完成。

回答by Bruno Bossola

So no way to fix this apparently. Took a look at the code, but apparently the buffer is contructed with a default size carved into the code.

所以显然没有办法解决这个问题。看了一下代码,但显然缓冲区是用代码中的默认大小构建的。

So, the only way to solve this, is to use Response::setBufferSize() from your code.

因此,解决此问题的唯一方法是使用代码中的 Response::setBufferSize()。

回答by Steve

Try the following setting in connector: socketBuffer="64000"

在连接器中尝试以下设置: socketBuffer="64000"

回答by Awadhesh Verma

To use "socket.appWriteBufSize" and "socket.appReadBufSize" attribute, your connector must be NIO connector. Change the value of "protocol" attribute from "HTTP/1.1" to "org.apache.coyote.http11.Http11NioProtocol".

要使用“socket.appWriteBufSize”和“socket.appReadBufSize”属性,您的连接器必须是 NIO 连接器。将“protocol”属性的值从“HTTP/1.1”改为“org.apache.coyote.http11.Http11NioProtocol”。