Question

In tomcat 6 i have a servlet running openbluedragon, everything compiles and servers up quik, with the exception of images, they really lag significantly. Any suggestions optimization for image serving?

Here is my server.xml:

    <Service name="Catalina">

      <Connector port="8009" protocol="AJP/1.3" />
      <Connector port="8080" maxThreads="100" protocol="HTTP/1.1" connectionTimeout="20000" />
      <Engine name="Standalone" defaultHost="hostname.whatever" jvmRoute="ajp13">

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      <Host name="hostname.whatever"  appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
        ...context
      </Host>

    </Engine>
  </Service>
Was it helpful?

Solution

Another option is to use apache as a frontend, connecting tomcat with mod_jk. This way you can let apache serve static content (e.g. images, css, javascript) and let tomcat generate the dynamic content. Might leave a bit of work to separate the static content from the dynamic ones, but works great for me.

On Unix, having an apache as frontend is a nice option because being bound to port 80 you're often forced to run as root. Apache knows how to drop root permissions after binding a port, Tomcat doesn't. You don't want a server faced to the public to run as root.

(This is similar to the reverse proxy answer, but doesn't involve a proxy but mod_jk)

OTHER TIPS

Are you serving the same set of images over and over? In that case adding a servlet filter that adds a reasonable Expires header might save tomcat a lot of work. It will not increase the speed of the served image but will just make the number of requests it has to handle less. Lots of examples for this on the web.

If you have the option, you could add a reverse proxy in advance of your application. At work I have an Apache web server that receives all inbound HTTP connections. Based on the URL, it either forwards the request to another server or serves up the content itself. I've used this approach to accelerate serving up static content for a Trac site. The ProxyPass and ProxyPassReverse directives are a good place to start looking if you want to go this route.

As a simple example, if you have a virtual directory called /images, Apache could serve up any request for something in that directory and forward everything else to your Tomcat instance. The syntax is pretty comprehensive. If there is any method at all to the way your static content is identified this is an approach that will work.

Apache isn't the only choice here. I think all modern web servers include similar functionality. If I was starting today I'd probably look at LigHTTPd instead, just because it does less.

There may even be caching reverse proxies that figure this out for you automatically. I'm not familiar with any of them though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top