views:

1435

answers:

4

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>
+3  A: 

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.

+3  A: 

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)

Olaf
thanks, i've looked into mod_jk, i know a lot of people use it, but it seems according to the benchmarking tomcats jio actually servers images and static content fast then through mod_jk...although is the images were seperated they would serve faster w\apache, worry that my java apps would slow down
ethyreal
+3  A: 

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.

Simon Groenewolt
A: 

Hi,

Can any one tell me how to seperate static and dynamic content in Apache. I mean for dynamic pages it has tp send requests to tomacat and for static content it has to serve directly. I am using mod_jk for apache tomcat connection.

I guess by using JKMount /businesspublisher* loadbalancer

For serving image content sirectly instead of requesting through apj port

JkUnMount /*.png loadbalancer

Here

Maruthi
Hi, welcome at Stackoverflow. You've used the "Post Your **Answer** " box to post a **question**. This isn't the right way to ask a question :) Go to the top right of this page, you'll note an `Ask Question` button. Press there to ask a question. Good luck. PS: don't forget to read the message formatting instructions.
BalusC