1

I have a domain that is hosted on an unmanaged VPS server with Ubuntu 16.04 I have configured my Java EE Tomcat web app to be served up at my domain name. But the response times for the app are way too slow, progressively going toward timeouts in the browser. If I stop the apache2 service and access my web app through domain:8080 the web app performance is perfect. How do you correctly configure apache2 to serve up the tomcat web app at the domain name with good performance? I realize that the easy solution is to link all references to my web app to domain:8080, but I would like to know how to correctly configure apache2 to serve up the Tomcat web app at the domain with the same performance as using domain:8080. Thanks in advance for any help.

This is my apache2 sites-available file for the domain:

<VirtualHost *:80>

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin webmaster@lae-laeweb.com
  ServerName  lae-laeweb.com
  ServerAlias www.lae-laeweb.com


  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html
  DocumentRoot /var/www/html


  # Custom log file locations
  LogLevel warn
  ErrorLog /var/log/apache2/error-lae-laeweb.com.log
  CustomLog /var/log/apache2/access-lae-laeweb.com.log combined

    #ServerName www.lae-laeweb.com

     ProxyRequests On
     ProxyPass / http://lae-laeweb.com:8080/LAEWeb/ keepalive=on ttl=60
     ProxyPassReverse / http://lae-laeweb.com:8080/LAEWeb/

    <Location />
        Order allow,deny
        Allow from all
    </Location>


</VirtualHost>

This is a script I use after uploading a new .war file for my web app to tomcat:

#!/bin/bash

cd ../usr/local/apache-tomcat-8.5.23/bin

./shutdown.sh

./startup.sh

cd ../../../..

service apache2 reload

service apache2 restart

service=apache2

if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running!!!"
else
/etc/init.d/$service restart
fi

server.xml for tomcat:

<?xml version="1.0" encoding="UTF-8"?>

<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />


  <GlobalNamingResources>

    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

   <Service name="Catalina">

     <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="60000"
               redirectPort="8443"
           maxThreads="200" acceptCount="100" />


    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" connectionTimeout="60000" />

    <Engine name="Catalina" defaultHost="lae-laeweb.com:8080">

      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>



<Host name="lae-laeweb.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
      <Alias>www.lae-laeweb.com</Alias>
      <Context path="" docBase="/usr/local/apache-tomcat-8.5.23/webapps/LAEWeb" debug="0" privileged="true" reloadable="true" />
      <Valve className="org.apache.catalina.valves.AccessLogValve"
             directory="logs"   prefix="localhost_access_log." suffix=".txt"
             pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />
</Host>

    </Engine>
  </Service>
</Server>
te7
  • 107
  • 1

2 Answers2

0

When using apache as a proxy that is subject to network delays you should tune buffering to improve performance. As available on the documentation, try adding this to your virtualhost file:

<VirtualHost *:80>

  ...

     ProxyRequests On
     ProxyReceiveBufferSize 512
     ProxyPass / http://lae-laeweb.com:8080/LAEWeb/ keepalive=on ttl=60
     ProxyPassReverse / http://lae-laeweb.com:8080/LAEWeb/

  ...

As suggested on the documentation, avoid values lower than 512 on the buffer and play around with higher values to see if you end up getting better performance. There's no one size fits all setting here.

Zip
  • 204
  • 1
  • 7
  • Thanks I appreciate that. Tried with different values. No help. Just sticking with domain:8080 links for now for production usage. Maybe someone has the answer though. – te7 Oct 15 '17 at 15:51
  • My Tomcat web app uses reflection to dynamically load different classes at different times but not simultaneously. These classes take significant memory. Maybe that's what apache is having trouble with. With accessing Tomcat directly the heap memory is maintained in the app code by deleting unused instances of classes and then doing garbage collection. Maybe also the garbage collection in my code is causing memory issues for apache. – te7 Oct 15 '17 at 18:17
  • But I can initialize tomcat and apache, and the web app at the domain name initially loads fine on the landing page (without calling any classes that use the memory). Then just after 10 or 12 page refreshes of this landing page the browser starts to time out. – te7 Oct 15 '17 at 18:55
  • But if after the landing page I choose options from it that will call the memory using classes the browser begins to time out almost immediately. – te7 Oct 15 '17 at 19:14
  • Can you check server logs on both apache and tomcat? – Zip Oct 15 '17 at 19:39
  • The logs I checked: tomcat showed JAVA_HOME error..fixed. Apache error log was 96 MB, and domain log was 10 MB. Caused considerable slow down. Add apache log clearing script to script above, and above script to crontab for every 15 minutes to re-initialize tomcat and apache. See how it goes. – te7 Oct 15 '17 at 23:19
-2

Found the problem. You have to set "ProxyRequests Off" in domain.conf file in apache2/sites-available folder. Everything working fine now. Thanks to all the posters. Much appreciated.

te7
  • 107
  • 1