Skip to content

Commit

Permalink
Merge pull request #81 from defold/increase-idle-timeout-attempt-2
Browse files Browse the repository at this point in the history
Increase Jetty idle timeout 30s -> 60s - attempt 2
  • Loading branch information
nasthu authored Jun 15, 2018
2 parents 18e8458 + 2725f7b commit df3c36b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

server:
port: 9000
jetty:
http.timeout: 60000

extender:
sdk-location: /var/extender/sdk
Expand Down

0 comments on commit df3c36b

Please sign in to comment.