Scaling a LAMP website hosted on EC2

amazon ec2load balancingmysql-replicationscaling

I'm very new to all this – I've recently managed to launch my website on EC2. As next step, I want to learn how to scale the website. I have a general idea but wanted some input from the experts about how to go about it.

My website is based on LAMP but also has Red5 server which allows users to record messages and also used for playing them back.

Currently this is the architecture I'm planning to setup for initial scaling. Deploy four small EC2 instances for the following purposes:

Instance-1:
On this instance I will run the MySql database

Instance-2:
On this instance I will run the red5 server

Instance-3 & Instance-4
These 2 instances will be used to deploy the website and will have Apache running on them. They will communicate with the mysql server on Instance-1 and red5 server on Instance-2 using the internal IP address. As an when required, I will launch another instance of the same

EBS
– I will have EBS of say 50 GIG where all the mysql data will be stored. Also red5 will use this EBS to store the video messages

Load-Balancer
– Use the load balancer provided by Amazon to load balance Instance-3 and Instance-4

This is what I have in mind. I could be way off so please bear with me.
Also I have not taken into account the case of scaling MySql server as I currently have no idea about how that will be done and whether or not it is necessary initially.

I am aware that Amazon provides auto scaling and mysql scaling as well but I dont want to get into that right now.

Your feedback is appreciated
Thanks

Best Answer

There's a whole series of articles on this topic @ http://highscalability.com

I haven't used AWS, but I have experience with running virtual instances in a datacenter, using rackspace virtual instances, and appengine.

How you scale (up vs. out) is greatly determined by what it is you're trying to do. Some apps will be i/o intensive, some will be cpu intensive. Your bottleneck might be inbound i/o, processing power, or backend i/o, or a combination of the three in varying amounts depending on where you are in your app's lifecycle. All will require a slightly different strategy.

Using something like AWS, in general you want to scale out and you have to begin with the end in mind and keep your apps loosely coupled. This will allow you to throw up another instance to scale to demand. It's fine to keep your db instance on the same instance as your main app when you're starting out, but that's usually the first thing to get spun off onto it's own server.

So you might start out with everything running on one instance. Then you start to get some traffic, and notice the database is eating up your cpu. So you move the database to another instance, and everything is great. Until you start to get more traffic... and you notice your front-end can't keep up with the traffic. So then you fire up a couple more instances, load balance them, and you're happy for a while, and scale up to maybe a dozen web servers... But then you get some more traffic, and while the front end is keeping up, now your database machine is starting to thrash. So then you replicate your database to a master and a couple of slaves, and everything is fine... and so on and so forth.

Related Topic