krause krause - 7 months ago 80
Java Question

Tomcat 8 not responsive serving static content

When deploying our application (Java, Spring) on Tomcat 7 it is fine. Now that we upgraded to Tomcat 8 it is very slow when serving static content. Looking at developer tools (see snapshot below), each request of static content (small .js and .css files) it takes as much as we have configured for connectionTimeout in server.xml. Because default is 20000, it may take 20 secs. for each file. When dropping this to 1000 it will be faster, and take 1 sec. for each one.

This happens in different development machines using default configurations. Other processes (web services requests, etc.) are performing ok.

I wonder what and where to start looking.

Developer tools snapshot

Answer

The plugin described below (pjl-comp-filter) was used as a CompressionFilter, which turned out not to be compatible with Tomcat 8 as per an open issue in Github for ziplet (its successor) : https://github.com/ziplet/ziplet/issues/6

I replaced it with one of these solutions and it worked :

Which compression (is GZIP the most popular) servlet filter would you suggest?

So former configuration, non working with Tomcat 8 was :

Dependency in pom.xml :

    <dependency>
        <groupId>org.sourceforge</groupId>
        <artifactId>pjl-comp-filter</artifactId>
    </dependency>

And web.xml :

<filter>
    <filter-name>CompressingFilter</filter-name>
    <filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
    <init-param>
        <param-name>includeContentTypes</param-name>
        <param-value>text/html,multipart/form-data,text/css,application/x-javascript</param-value>
    </init-param>
    <init-param>
        <param-name>compressionThreshold</param-name>
        <param-value>256</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>CompressingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>