New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration properties for configuring Tomcat's keep-alive timeout and max keep-alive requests #25815
Conversation
e04d5a1
to
3784c68
Compare
and maxKeepAliveRequests See spring-projects#25805
@parviz-93 Thank you very much for making your first contribution to Spring Boot. Your changes have now been merged along with a small polishing commit. |
@wilkinsona Thanks a lot for this experience. Thanks a lot for this experience. If there are still such tasks, I am ready to contribute to my favorite framework |
It looks like the keep-alive timeout only worked for HTTP/1.1. The timeout for HTTP/2 was still 20s. This is how I got around it based on a @shunminli example: @Configuration
public class TomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory>
{
@Value("${server.http.keep-alive-timeout:}")
private int httpKeepAliveTimeout;
@Value("${server.http2.keep-alive-timeout:}")
private long http2KeepAliveTimeout;
private static final Logger log = LoggerFactory.getLogger(TomcatCustomizer.class);
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addConnectorCustomizers(connector -> {
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
int originMaxKeepAliveRequests = protocol.getMaxKeepAliveRequests();
protocol.setMaxKeepAliveRequests(-1);
int originKeepAliveTimeout = protocol.getKeepAliveTimeout();
protocol.setKeepAliveTimeout(httpKeepAliveTimeout);
log.info(
"####################################################################################");
log.info("#");
log.info("# TomcatCustomizer HTTP");
log.info("#");
log.info("# origin maxKeepAliveRequests {}", originMaxKeepAliveRequests);
log.info("# custom maxKeepAliveRequests {}", protocol.getMaxKeepAliveRequests());
log.info("# origin keepalive timeout: {} ms", originKeepAliveTimeout);
log.info("# keepalive timeout: {} ms", protocol.getKeepAliveTimeout());
log.info("# connection timeout: {} ms", protocol.getConnectionTimeout());
log.info("# max connections: {}", protocol.getMaxConnections());
log.info("#");
log.info(
"####################################################################################");
});
factory.addConnectorCustomizers(connector -> {
Http2Protocol protocol = (Http2Protocol) connector.findUpgradeProtocols()[0];
long originKeepAliveTimeout = protocol.getKeepAliveTimeout();
protocol.setKeepAliveTimeout(http2KeepAliveTimeout);
log.info(
"####################################################################################");
log.info("#");
log.info("# TomcatCustomizer HTTP/2");
log.info("#");
log.info("# origin keepalive timeout: {} ms", originKeepAliveTimeout);
log.info("# keepalive timeout: {} ms", protocol.getKeepAliveTimeout());
log.info("#");
log.info(
"####################################################################################");
});
}
} |
@aplatt it sounds like these properties should also cover the HTTP/2 protocol. Could you create a new issue for that? |
I created issue #30267 |
and maxKeepAliveRequests
See #23539