Skip to content

Commit 2ac76b3

Browse files
committed
Merge pull request #15054 from ayudovin
* pr/15054: Polish contribution Add configuration property for configuring Tomcat's processor cache
2 parents 2f4751a + 1b40b0e commit 2ac76b3

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-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
}
@@ -134,6 +136,13 @@ private void customizeAcceptCount(ConfigurableTomcatWebServerFactory factory,
134136
});
135137
}
136138

139+
private void customizeProcessorCache(ConfigurableTomcatWebServerFactory factory,
140+
int processorCache) {
141+
factory.addConnectorCustomizers((
142+
connector) -> ((AbstractHttp11Protocol<?>) connector.getProtocolHandler())
143+
.setProcessorCache(processorCache));
144+
}
145+
137146
private void customizeMaxConnections(ConfigurableTomcatWebServerFactory factory,
138147
int maxConnections) {
139148
factory.addConnectorCustomizers((connector) -> {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ public void tomcatAcceptCountMatchesProtocolDefault() throws Exception {
206206
.isEqualTo(getDefaultProtocol().getAcceptCount());
207207
}
208208

209+
@Test
210+
public void tomcatProcessorCacheMatchesProtocolDefault() throws Exception {
211+
assertThat(this.properties.getTomcat().getProcessorCache())
212+
.isEqualTo(getDefaultProtocol().getProcessorCache());
213+
}
214+
209215
@Test
210216
public void tomcatMaxConnectionsMatchesProtocolDefault() throws Exception {
211217
assertThat(this.properties.getTomcat().getMaxConnections())

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=200 # 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)