Tweak Tomcat performance

This commit does the following things :

* Increase Tomcat resource cache size to be able to actually store
  something in there.
* Increase Tomcat resource cache TTL to avoid costly evictions
* Put Jasper in production mode to avoid recompiling JSPs
master
François-Xavier Thomas 8 years ago
parent 2948ae0f78
commit 7326378f0a
No known key found for this signature in database
GPG Key ID: 64337406D2DD45CE
  1. 36
      libresonic-main/src/main/java/org/libresonic/player/boot/Application.java

@ -1,6 +1,9 @@
package org.libresonic.player.boot; package org.libresonic.player.boot;
import net.sf.ehcache.constructs.web.ShutdownListener; import net.sf.ehcache.constructs.web.ShutdownListener;
import org.apache.catalina.Container;
import org.apache.catalina.Wrapper;
import org.apache.catalina.webresources.StandardRoot;
import org.directwebremoting.servlet.DwrServlet; import org.directwebremoting.servlet.DwrServlet;
import org.libresonic.player.filter.*; import org.libresonic.player.filter.*;
import org.libresonic.player.spring.LibresonicPropertySourceConfigurer; import org.libresonic.player.spring.LibresonicPropertySourceConfigurer;
@ -11,6 +14,10 @@ import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.boot.web.support.SpringBootServletInitializer;
@ -32,7 +39,7 @@ import javax.servlet.ServletContextListener;
"classpath:/applicationContext-cache.xml", "classpath:/applicationContext-cache.xml",
"classpath:/applicationContext-sonos.xml", "classpath:/applicationContext-sonos.xml",
"classpath:/libresonic-servlet.xml"}) "classpath:/libresonic-servlet.xml"})
public class Application extends SpringBootServletInitializer { public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
/** /**
* Registers the DWR servlet. * Registers the DWR servlet.
@ -163,6 +170,33 @@ public class Application extends SpringBootServletInitializer {
return doConfigure(application); return doConfigure(application);
} }
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory tomcatFactory = (TomcatEmbeddedServletContainerFactory) container;
tomcatFactory.addContextCustomizers((TomcatContextCustomizer) context -> {
// Increase the size and time before eviction of the Tomcat
// cache so that resources aren't uncompressed too often.
// See https://github.com/jhipster/generator-jhipster/issues/3995
StandardRoot resources = new StandardRoot();
resources.setCacheMaxSize(100000);
resources.setCacheObjectMaxSize(4000);
resources.setCacheTtl(24 * 3600 * 1000); // 1 day, in milliseconds
context.setResources(resources);
// Put Jasper in production mode so that JSP aren't recompiled
// on each request.
// See http://stackoverflow.com/questions/29653326/spring-boot-application-slow-because-of-jsp-compilation
Container jsp = context.findChild("jsp");
if (jsp instanceof Wrapper) {
((Wrapper)jsp).addInitParameter("development", "false");
}
});
}
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplicationBuilder builder = new SpringApplicationBuilder(); SpringApplicationBuilder builder = new SpringApplicationBuilder();
doConfigure(builder).run(args); doConfigure(builder).run(args);

Loading…
Cancel
Save