Skip to content

Commit 3059f0e

Browse files
ayudovinsnicoll
authored andcommitted
Add configuration property for configuring Tomcat's processor cache
See gh-15054
1 parent 2f4751a commit 3059f0e

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* @author Brian Clozel
5757
* @author Olivier Lamy
5858
* @author Chentao Qu
59+
* @author Artsiom Yudovin
5960
*/
6061
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
6162
public class ServerProperties {
@@ -369,6 +370,12 @@ public static class Tomcat {
369370
*/
370371
private int acceptCount = 100;
371372

373+
/**
374+
* Maximum number of idle processors that will be retained in the cache and reused
375+
* with a subsequent request.
376+
*/
377+
private int processorCache = 200;
378+
372379
/**
373380
* Comma-separated list of additional patterns that match jars to ignore for TLD
374381
* scanning. The special '?' and '*' characters can be used in the pattern to
@@ -524,6 +531,14 @@ public void setAcceptCount(int acceptCount) {
524531
this.acceptCount = acceptCount;
525532
}
526533

534+
public int getProcessorCache() {
535+
return this.processorCache;
536+
}
537+
538+
public void setProcessorCache(int processorCache) {
539+
this.processorCache = processorCache;
540+
}
541+
527542
public List<String> getAdditionalTldSkipPatterns() {
528543
return this.additionalTldSkipPatterns;
529544
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
108108
.to((maxConnections) -> customizeMaxConnections(factory, maxConnections));
109109
propertyMapper.from(tomcatProperties::getAcceptCount).when(this::isPositive)
110110
.to((acceptCount) -> customizeAcceptCount(factory, acceptCount));
111+
propertyMapper.from(tomcatProperties::getProcessorCache).when(this::isPositive)
112+
.to((processorCache) -> customizeProcessorCache(factory, processorCache));
111113
customizeStaticResources(factory);
112114
customizeErrorReportValve(properties.getError(), factory);
113115
}
@@ -156,6 +158,13 @@ private void customizeConnectionTimeout(ConfigurableTomcatWebServerFactory facto
156158
});
157159
}
158160

161+
private void customizeProcessorCache(ConfigurableTomcatWebServerFactory factory,
162+
int processorCache) {
163+
factory.addConnectorCustomizers((
164+
connector) -> ((AbstractHttp11Protocol<?>) connector.getProtocolHandler())
165+
.setProcessorCache(processorCache));
166+
}
167+
159168
private void customizeRemoteIpValve(ConfigurableTomcatWebServerFactory factory) {
160169
Tomcat tomcatProperties = this.serverProperties.getTomcat();
161170
String protocolHeader = tomcatProperties.getProtocolHeader();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public void customAcceptCount() {
8787
.isEqualTo(10));
8888
}
8989

90+
@Test
91+
public void customProcessorCache() {
92+
bind("server.tomcat.processor-cache=100");
93+
assertThat(this.serverProperties.getTomcat().getProcessorCache()).isEqualTo(100);
94+
}
95+
9096
@Test
9197
public void customBackgroundProcessorDelay() {
9298
bind("server.tomcat.background-processor-delay=5");

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ content into your application. Rather, pick only the properties that you need.
276276
server.tomcat.max-threads=200 # Maximum amount of worker threads.
277277
server.tomcat.min-spare-threads=10 # Minimum amount of worker threads.
278278
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
279+
server.tomcat.processor-cache= # Maximum number of idle processors that will be retained in the cache and reused with a subsequent request.
279280
server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
280281
server.tomcat.protocol-header-https-value=https # Value of the protocol header indicating whether the incoming request uses SSL.
281282
server.tomcat.redirect-context-root=true # Whether requests to the context root should be redirected by appending a / to the path.

0 commit comments

Comments
 (0)