h1. Running a web-farm on Mesos in your private cluster

Mesos comes with a framework written in Python that will run a web load balancer ("HAProxy":http://haproxy.1wt.eu) and use apache for the backend servers. The framework is in MESOS_HOME/frameworks/haproxy+apache. There is a README in that directory that might be slightly helpful, but we recommend looking a the framework scheduler and executor code to familiarize yourself with the concepts behind the framework.

HAProxy has this annoying artifact that in order to ramp up and down in the number of servers it is load balancing between it has to kill the existing running HAProxy process and start a new one, which inevitably leads to dropped connections. Some people have looked into ways to get around the dropped connections (see this animoto blog post about adding/removing servers to haproxy: http://labs.animoto.com/2010/03/10/uptime-with-haproxy).

We recommend checking out other load balancers as well. Basically, whatever load balancer you're using, the framework scheduler should query the statistics of the load balancer to figure out how many web requests are being served to it and then ramp up and down the number of web server tasks based on those statistics. We've also written a framework that uses "Linux Virtual Server (LVS)":http://www.linux-vs.org as the load balancer. LVS can be run in three different modes, and any should work with Mesos.

h1. Running a web farm on Mesos on EC2

h2. Why use Mesos on EC2?

Many might wonder what the advantages of running a Mesos web farm on EC2 are over simply using the Amazon Elastic Load Balancer which will automatically ramp up and down the number of back end web server AMIs for you. We have found that by running Mesos on top of EC2 we are able to share a single EC2 instance between our web frameworks and our other frameworks such as Hadoop or Spark which can be used to do data analytics on top of the click logs being generated by the web frameworks, for instance.

We have also found that we can allow multiple different users share an EC2 allocation of instances much more efficiently (and thus reduce EC2 costs) by using Mesos on that EC2 allocation.

h2. Where to look to get started

We have also successfully used Amazon's Elastic Load Balancer instead of HAProxy. This is still in a non-master development branch called "andyk-elb+apache-notorque":https://github.com/mesos/mesos/tree/andyk-elb+apache-notorque. You will need to set up a Mesos EC2 cluster and the framework uses python boto to connect to Amazon's CloudWatch and EC2 so you will need to create a credentials file for boto to be able to connect to those amazon services correctly from the node on which you run the framework.

Watch out when using ELB however, since it displays some interesting and non-intuitive behavior when ramping up and down (though it doesn't drop connections like HAProxy does out of the box). See this blog post: http://shlomoswidler.com/2009/07/elastic-in-elastic-load-balancing-elb.html for details about how ELB ramps up and down and especially read it if you plan on. 
