Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scale a PHP application (servers, mysql, memcache)

I'm currently creating a website for a social project in switzerland.

And before there is an overflow of user, I want to prepare the application to scale.

I answered by myself many questions but some are left.

I explain what I want to do.


First

at the beginnning, the Application will have only one server (short time) with DNS, PHP, Mysql, Data, and memcache.


Second

Then I will split them in two

  1. DNS, Mysql, memcache
  2. Data, PHP

Third

Here is the problem, I don't know how to do it exactly here to keep the application running well.

I could do :

  1. Front : Load Balancer, memcache, DNS
  2. Web 1 : PHP, DATA
  3. Web 2 : PHP, DATA
  4. Mysql

This would be the scheme, all PHP sessions are kept in the DB.

BUT, how do I sync the data? do I run a Rsync to keep them up to date. do I put them on a separate disk (network disk) to be sure ? but in this case, how can I do in case of user uploads ?

and if the website gets more success and we have to go on greater structures, would'nt it create some latency on updates ?

or would it be a good thing to go directly to amazon's web services ?

some infos I use codeigniter as Framework. I use linux as webserver (distribution not chosen now, but should be Debian)

Thanks in advance for your answers.

like image 455
Stéphane Goetz Avatar asked Apr 15 '10 17:04

Stéphane Goetz


2 Answers

According to Wikipedia, Switzerland has 4.6 million German speakers, 1.5 million French speakers, and .5 million speakers of Italian, Romansch and other languages. So I suspect you'll find that a single server will fit your needs. Guess what percentage of the population will visit your site every month or every day to get a sense of how big you can get before running into scaling issues.

So, I don't think you need to worry about scaling yet! Bonus: The time you don't spend worrying about this problem, you can use to solve other problems for your users.

like image 110
Summer Avatar answered Oct 12 '22 23:10

Summer


There are a few common paths to scaling web services up, in order of what sites like Flickr and Facebook seem to use:

  • Split servers based on concepts (API, login, media files, ads, static pages, dynamic pages)
  • Split databases based on concepts that don't need to be JOINed (logins, long term reporting, page data, etc.)
  • Compile/optimize your PHP and other resources (sprites, compiled css, zend)
  • Add caching (front end, back end)
  • Add delegation (round robin, etc.)

But, before scaling, measure. Set of tests, calculate your capacity, and don't optimize before you need to.

like image 22
Bruce Alderson Avatar answered Oct 12 '22 23:10

Bruce Alderson