Upgrading your Play! applications without downtime

Monday, March 8, 2010

You have your Play! application deployed on production. It is a real success and you have loads of users. You are really happy, and, as Play! is quite fast you don't have any performance issue yet :)

However, you are receiving feature requests. Being an Agile developer, you implement them quickly, test them in acceptance and you are ready to let your users enjoy them. But, your web applications is so successful that you don't really want to plan a downtime...

Though choice, new features to keep your users happy or 100% uptime? Well it is quite simple to do both using Play!. This is because Play! is fully stateless.

My Play! web applications always use a front end proxy. Apache being the most popular I will illustrate how to do it with this web server.

The basic idea is to run 2 Play! instances of your web application and let the front end proxy load balance them. In case one is not available, it will forward all the requests to the available one.

Let's start our the same Play! application two times: one on port 9999 and one on port 9998.

I actually copied my application 2 times and edited the application.conf in the conf directory to change the port numbers.

For each web application directory:
play start mysuperwebapp

Now, let's configure our Apache web server to have a load balancer.

In Apache, I have the following configuration:

<VirtualHost mysuperwebapp.com:80>
ServerName mysuperwebapp.com
<Location /balancer-manager>
SetHandler balancer-manager

Order Deny,Allow
Deny from all
Allow from .mysuperwebapp.com

<Proxy balancer://mycluster>
BalancerMember http://localhost:9999
BalancerMember http://localhost:9998 status=+H

<Proxy *>
Order Allow,Deny
Allow From All
ProxyPreserveHost On
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / http://localhost:9999/
ProxyPassReverse / http://localhost:9998/


The important part is balancer://mycluster. This declares a load balancer. The +H option means that the second Play! application is on stand-by. It will take over if the first one fails. This is exactly what I want.

Everytime I want to upgrade mysuperwebapp, here what I am doing:
play stop mysuperwebapp1

The load-balancer then forward everything to mysuperwebapp2. In the meantime I am updating mysuperwebapp1. Once I am done:
play start mysuperwebapp1

And I can now safely update mysuperwebapp2.

Apache also provides a way to view the status of your cluster. Simply point your browser to /balancer-manager to view the current status of your clusters.

Because Play! is completely stateless you don't have to manage sessions between the 2 clusters. You can actually easily scale to more than 2 play! instances. As we have seen, that is really easy to do.

Happy Play!


About This Blog

  © Blogger template Writer's Blog by Ourblogtemplates.com 2008

Back to TOP