Skip to content

RunningTheWebappInTomcat

Andrew Byrd edited this page Aug 12, 2013 · 11 revisions

First, you will need to configure the opentripplanner-api-webapp with information about the location of your graph file, as well as some routing settings. See ConfiguringTheWebapp for more details.

Next, install Tomcat 6 in whatever way you prefer if it is not already present on your system. Apt-get works great on Debian-based systems.

You will usually need to increase the amount of memory available to Tomcat. This is usually done by editing the file /etc/default/tomcat6 or /etc/default/tomcat7 on the line starting JAVA_OPTS= and increasing the -Xmx parameter (often to several gigabytes for larger cities), before starting or restarting the server.

Build OTP (including the webapp) using mvn package -DskipTests.

Use the Tomcat manager webapp to upload the opentripplanner-webapp.war and opentripplanner-api-webapp.war files.

Request Handling Threads

OTP has the peculiar characteristic of near-100% CPU usage and high memory consumption for each request handled. In order to prevent excessive memory consumption from many simultaneous searches, the servlet container hosting OTP should be configured to handle requests sequentially, rather than in parallel as is common for I/O bound server tasks. We have also observed that OTP scales very well vertically, nearly linearly in the number of processor cores given sufficient memory.

Tomcat can be reconfigured based on these characteristics. We set the number of request handling threads to the number of available cores in the machine, and then make the request queue quite long so incoming requests wait in line to be handled one by one. Changes must be made to the maxThreads and acceptCount attributes of the connector element in /etc/tomcat7/server.xml:

    <Connector port="8080" protocol="HTTP/1.1" 
               maxThreads="4"
               acceptCount="200"
               connectionTimeout="20000" 
               URIEncoding="UTF-8"
               redirectPort="8443" />

Security

If you are using Tomcat security, edit your Tomcat security policy, which probably lives in /etc/tomcat6/policy.d/*.policy .

Add the following:

grant codeBase "file:${catalina.base}/webapps/opentripplanner-api-webapp/-" {
    permission java.io.FilePermission "/var/lib/opentripplanner/-","read"; /* location of Graph.obj */`
     
    permission java.util.PropertyPermission "org.apache.commons.logging.LogFactory.HashtableImpl", "read";
    permission java.util.PropertyPermission "com.sun.jersey.core.util.ReaderWriter.BufferSize", "read";
    
    permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect.generics.reflectiveObjects";

    /* there aren't fatal -> webapp still runs w/o them... */
    permission java.util.PropertyPermission "org.geotools.referencing.epsg-datasource", "read";
    permission java.util.PropertyPermission "org.geotools.referencing.crs-directory", "read";
    permission java.util.PropertyPermission "org.geotools.referencing.forceXY", "read";
    
    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
    
    permission java.lang.RuntimePermission "shutdownHooks";
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.tomcat.util.http";
};

The documentation on this wiki is outdated and should not be used

unless you are intentionally working with legacy versions of OpenTripPlanner. Please consult the current documentation at readthedocs

Clone this wiki locally