Tomcat – significant page load speed difference : directly accessing Tomcat (localhost) VS accessing tomcat via Apache (mod_jk connector)

apache-2.2mod-jktomcat

I have a tomcat v6 which contains 2 web applications (JSF2.0 and JSP). The physical server is RedHat Enterprise with 16GB memory.

In current form, the tomcat is exposed to the internet via apache 2.2 and we're by using mod_jk v1.28 connector. so in essence when a user types in www1.example.com/myWebApp where webApp has been configured in httpd.conf as worker1 which in turn points to above mentioned tomcat v6 above listening on port 8009 to handle the request.

Tomcat server.xml has the following relevant bits:

 <Connector port="8080"
             protocol="HTTP/1.1"
             maxThreads="150"
             connectionTimeout="20000"
             redirectPort="8443"
  />

 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

in workers.properties worker1 has been configured as:

worker.worker1.type = ajp13
worker.worker1.host =localhost
worker.worker1.port = 8009

and in httpd.conf :

JkMount     /myWebApp/* worker1

In testing the page load speeds, when i access the web application by accessing the above tomcat directly using its localhost address (localhost:8080/myWebApp), the web application is fast and page load averages about 2-3 seconds max.

Now if i access the same web application, on same network except this time by going via apache (www1.example.com/myWebApp) the page is visibly slower and page load speed average between 10-12 seconds.

is this normal? I am suspecting that the leg work that happens between apache ---> mod_jk --> tomcat v6 to handle any given request is adding up to the slow speeds? Can someone suggest ways in which i can improve the responsiveness of the web applications when requesting are coming from apache?

UPDATE:

DNS lookup delays is out of question given www1.example.com which is mapped to our local IP address so there is definitely no DNS look up delays contributing to this delay.

Best Answer

Try testing on the localhost hostname first:

i.e with the localhost hostname via Apache. If it is faster, then you know you have a DNS issue.

If it is still slow try using mod_proxy to reverse proxy requests to 8080 and see if that slow e.g.

so firstly do

a2enmod proxy

and then in your VirtualHost (put in a separate conf, don't use http.conf), and remove the JKMount from http.conf

ProxyPassReverse /myWebApp/ http://localhost:8080/myWebApp/

If it isn't then you know its the AJP connector. It it is, then their is something else on your Apache server causing the problem