From 2725f7bda06d94730570f90f5def4ef0fb9a1d32 Mon Sep 17 00:00:00 2001 From: Jonas Thurfors Date: Wed, 13 Jun 2018 16:41:32 +0200 Subject: [PATCH] Increase Jetty idle timeout 30s -> 60s attempt 2 (Spring only supports a subset of Jetty configuration props, so configure idle timeout programatically) --- .../defold/extender/ExtenderApplication.java | 21 ++++++++++++++++++- server/src/main/resources/application.yml | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/defold/extender/ExtenderApplication.java b/server/src/main/java/com/defold/extender/ExtenderApplication.java index 0599cc7c..82ad1214 100644 --- a/server/src/main/java/com/defold/extender/ExtenderApplication.java +++ b/server/src/main/java/com/defold/extender/ExtenderApplication.java @@ -1,16 +1,20 @@ package com.defold.extender; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.influxdb.InfluxDB; import org.influxdb.InfluxDBFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter; import org.springframework.boot.actuate.endpoint.MetricsEndpoint; import org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader; import org.springframework.boot.actuate.metrics.writer.GaugeWriter; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.core.env.Environment; @@ -20,12 +24,16 @@ @SpringBootApplication public class ExtenderApplication { + private static final Logger LOGGER = LoggerFactory.getLogger(ExtenderApplication.class); + private final Environment environment; + private final int idleTimeout; @Autowired - public ExtenderApplication(Environment environment) { + public ExtenderApplication(Environment environment, @Value("${server.jetty.http.timeout}") int idleTimeout) { this.environment = environment; + this.idleTimeout = idleTimeout; } public static void main(String[] args) throws IOException, InterruptedException { @@ -74,4 +82,15 @@ GaugeWriter influxMetricsWriter() { public MetricsEndpointMetricReader metricsEndpointMetricReader(MetricsEndpoint metricsEndpoint) { return new MetricsEndpointMetricReader(metricsEndpoint); } + + // Spring Boot only supports a subset of Jetty configuration props, so configure idle timeout programatically + @Bean + public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() { + final JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(); + factory.addServerCustomizers((Server server) -> { + final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class); + threadPool.setIdleTimeout(idleTimeout); + }); + return factory; + } } diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 582cef35..91a656d7 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -1,6 +1,8 @@ server: port: 9000 + jetty: + http.timeout: 60000 extender: sdk-location: /var/extender/sdk