From 48d3e5101cf42dde385ed8e880e2e3fb0ce03f31 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 30 May 2023 14:58:39 +0200 Subject: [PATCH] SEBSERV-445 adapt Tomcat connector settings --- .../java/ch/ethz/seb/sebserver/SEBServer.java | 26 +++++++++++++++++++ .../gbl/async/AsyncServiceSpringConfig.java | 1 + .../config/application-dev-ws.properties | 2 +- .../resources/config/application.properties | 4 +++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/SEBServer.java b/src/main/java/ch/ethz/seb/sebserver/SEBServer.java index da12f52d..6e630bd0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/SEBServer.java +++ b/src/main/java/ch/ethz/seb/sebserver/SEBServer.java @@ -10,10 +10,13 @@ package ch.ethz.seb.sebserver; import org.apache.catalina.connector.Connector; import org.apache.commons.lang3.BooleanUtils; +import org.apache.coyote.http11.AbstractHttp11Protocol; +import org.apache.coyote.http11.Http11NioProtocol; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -84,6 +87,29 @@ public class SEBServer { return firewall; } + @Bean + public WebServerFactoryCustomizer tomcatCustomizer() { + return (tomcat) -> tomcat.addConnectorCustomizers((connector) -> { + if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) { + System.out.println("*************** tomcatCustomizer"); + final AbstractHttp11Protocol protocolHandler = (AbstractHttp11Protocol) connector + .getProtocolHandler(); + protocolHandler.setKeepAliveTimeout(60000); + protocolHandler.setMaxKeepAliveRequests(3000); + protocolHandler.setUseKeepAliveResponseHeader(true); + protocolHandler.setMinSpareThreads(200); + protocolHandler.setProcessorCache(-1); + protocolHandler.setTcpNoDelay(true); + protocolHandler.setThreadPriority(Thread.NORM_PRIORITY + 1); + if (protocolHandler instanceof Http11NioProtocol) { + System.out.println("*************** Http11NioProtocol"); + ((Http11NioProtocol) protocolHandler).setPollerThreadPriority(Thread.MAX_PRIORITY); + } + + } + }); + } + private Connector redirectConnector(final Environment env) { final String sslPort = env.getRequiredProperty("server.port"); final String httpPort = env.getProperty("sebserver.ssl.redirect.html.port", "80"); diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java b/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java index 4f750ff1..50a20ce3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java @@ -34,6 +34,7 @@ public class AsyncServiceSpringConfig implements AsyncConfigurer { executor.setMaxPoolSize(42); executor.setQueueCapacity(11); executor.setThreadNamePrefix("asyncService-"); + executor.setThreadPriority(Thread.NORM_PRIORITY); executor.initialize(); executor.setWaitForTasksToCompleteOnShutdown(true); return executor; diff --git a/src/main/resources/config/application-dev-ws.properties b/src/main/resources/config/application-dev-ws.properties index 1840c26a..25b871d9 100644 --- a/src/main/resources/config/application-dev-ws.properties +++ b/src/main/resources/config/application-dev-ws.properties @@ -25,7 +25,7 @@ sebserver.webservice.clean-db-on-startup=false # webservice configuration sebserver.init.adminaccount.gen-on-init=false -sebserver.webservice.distributed=false +sebserver.webservice.distributed=true #sebserver.webservice.master.delay.threshold=10000 sebserver.webservice.http.external.scheme=http sebserver.webservice.http.external.servername=localhost diff --git a/src/main/resources/config/application.properties b/src/main/resources/config/application.properties index 2f6bd64a..0079b89b 100644 --- a/src/main/resources/config/application.properties +++ b/src/main/resources/config/application.properties @@ -15,6 +15,10 @@ server.servlet.context-path=/ # Tomcat server.tomcat.max-threads=2000 server.tomcat.accept-count=300 +socket.soKeepAlive=true +socket.performanceConnectionTime=1 +socket.performanceLatency=2 +socket.performanceBandwidth=0 server.tomcat.uri-encoding=UTF-8 ### encoding