Weird Tomcat behaviour when running two instances

I have two instances of openmrs 1.9.9 running on tomcat 6 , and notice once in a while one is stopped by tomcat and needs to be restarted . i suspect that this is a memory issue but wonder if anyone has had this issue before

I wonder why do you need 2 instances of the same webapp in the same application server.

I doubt if that is actually possible, support for running multiple openmrs instances was added in master recently, so it is not possible in older versions

you mean its not possible to run openmrs1 and openmrs 2 on the same instance?

so judy.com/openmrs1

and judy.com/openmrs2

I have been able to deploy this on 1.9.9

We have been doing this for a long time on our demo server and right now have four separate instances of OpenMRS running concurrently under the same Tomcat 7 instance.

@judy We support what you are trying to do by the following (on Ubuntu):

  1. Install each OpenMRS webapp normally in tomcat7 but don’t start them
  2. Edit each WEB-INF/web.xml file (found at /var/lib/tomcat7/webapps/AppName) to add the following:
<context-param>
     <param-name>webAppRootKey</param-name>
     <param-value>AppName</param-value>
</context-param>
  1. Update the following in the same file:
 <context-param>
  <param-name>application.data.directory</param-name>
  <param-value>/usr/share/tomcat7/AppName</param-value>
 </context-param>
  1. Create/Move your runtime.properties file to home tomcat folder (/var/lib/tomcat7 for me) and name it: AppName-runtime.properties

This is working for us with OpenMRS 1.9.4, 1.10.0, and 1.11.2 so feel free to ask if you have any questions or run into issues.

1 Like

Out of curiosity, what’s the advantage of having multiple instances of the webapp?

Our modules (OpenHMIS) need to support different versions of OpenMRS and this lets us more easily test and demo that. We also wanted to support demos of the released versions of our modules as well as the in-development versions.

Makes sense, I guess you have also 3 separate DBs.

Yup, that’s right. We have a separate database for each instance.

It will probably be more stable if you run two separate instances of tomcat.

@ibewes, what you described is what exactly we added to make it happen out of the box in the openmrs core master branch , i guess my point was that unless you make those tweaks you can’t be able to do so.

1 Like

That’s really good to know. Are those changes going to make it into the next platform release?

That’s a good question, actually the changes we made in core differ a little. Given that the next release of the platform is very likely to be 1.12.0, which will not be everything that is in master but rather 1.11+(carefully picked changes) from master, it means some tickets like this related one can easily be over looked:

@darius, @burke are you aware of the strategy we will use to pick what goes from master to the to be created 1.12.x branch? I guess we should probably start tagging such tickets so we can start keeping track of them.

On the other hand, i believe this is something we can back port to other maintenance branches since the changes that were made are minimal.

I’ve seen multiple threads at the tomcat and jboss mailing lists on this, but lazy to link them here. It is recommended that you run multiple web applications in the same container, rather than running multiple containers.

@ibewes

I made the changes you suggested , but the tomcat keeps causing a memory leak error that causes it to shut down

SEVERE: The web application [/judy2] appears to have started a thread named [Thread-2] but has failed to stop it. This is very likely to create a memory leak.

I am on tomcat 7 , do you have this problem?

Wes i keep getting errors - could you double check these settings

context-param>
     <param-name>webAppRootKey</param-name>
     <param-value>AppName</param-value>
</context-param>
Update the following in the same file:

 <context-param>
    <param-name>application.data.directory</param-name>
    <param-value>/usr/share/tomcat7/AppName</param-value>
 </context-param>

That’s true if the number of users is low, but doesn’t scale well and it’s a single point of failure. A usual architecture is a load balancer (an Apache) and multiple application servers. But I guess we don’t need any of that :slight_smile:

1 Like

@judy That looks correct. On our instance of OpenMRS called openmrs2 I made the following updates:

Custom Settings: /var/lib/tomcat7/webapps/openmrs2/WEB-INF/web.xml

  Added:
    <context-param>
      <param-name>webAppRootKey</param-name>
      <param-value>openmrs2</param-value>
    </context-param>
  Updated:
    <context-param>
      <param-name>application.data.directory</param-name>
      <param-value>/usr/share/tomcat7/.OpenMRS2</param-value>
    </context-param>
1 Like

@judy We are not getting that memory leak error. This shouldn’t have any effect on a memory leak (aside from maybe pushing off any affect) but we have given more memory to tomcat to ensure that it has enough to utilize for all the instances; 4GB spread across the various memory buckets that Java has.

Thanks @ibewes

I have centos so my settings are as below

tomcat is at /usr/share/tomcat7/

so i edited the web.xml of each instance

then

Added:
	  <context-param>
	    <param-name>webAppRootKey</param-name>
	    <param-value>openmrs2</param-value>
	  </context-param>
	Updated:
	  <context-param>
	    <param-name>application.data.directory</param-name>
	    <param-value>/usr/share/tomcat7/.OpenMRS2</param-value>
	  </context-param>

I made it as OpenMRS for the folder instead of .OpenMRS (no wonder i cannot find my modules)

I just placed my properties file in the webapps folder