Sunday, May 15, 2011

My answer to "Some questions regarding lampcms"

This is my answer to a Question on Support site for LampCMS project


Lampcms Can handle such load if you do few things right:
1) Do NOT run php as mod_php under apache. Instead run it as fastcgi, and not only that, but also run it under control of php-fpm. php-fpm comes with php 5.3.3 now, so you should just set it up. Make sure you have anough ram on the server and allocate about 250 php processors to run. This will be more than enough because 1000 requests are not really at the same time - php will not take more than 1/4 second per page on Lampcms, some pages are rendered in under 50 millisends here! This is true, even though my server is just plain dual core, 2 hard drives....

You can still use Apache but do not use mod_php, configure it to run php as fastcgi.
Ideally you should use NGINX or Lighttpd server for php - they are capable of handling much higher load.

2) Always use APC. This is one of the easiest thing is the world to do. APC is not even a server - you don't need to start it up, all you have to do is make sure apc extension is enabled in php.ini (and of cause you must have apc extension installed)

3) For best results run MongoDB on separate server, but make sure it's really close to the web server, I mean on the same subnet. This is not necessary, you can perfectly run the MongoDB and web server together on one box, just make sure you have enough RAM. I recommend minimum of 16Gig if you run Mongo and Web server together.

4) Scaling will be done mostly by MongoDB - it supports "horizontal scaling", which basically means "Just add another server" and with minimal or even no downtime. MongoDB will take care of it, you need to know how to do this of cause. You can learn more on MongoDB site and on their discussion list.

You can also scale by adding extra web server. One of the easiest things to do is to have dedicated server for images, JavaScript and css files. LampCMS supports this and even has config options in !config.ini to define urls of Image and CSS servers.

For serving static files Apache is preferred choice is it has excellent in-memory cache module, which you should always use for static files.

If you need to add more web servers then there are ways to do that too. There are some common time-tested ways to do this like round robin DNS. Just install copies on Lampcms scripts on several servers, point them to the same MongoDB database or cluster of databases and you should be able to handle millions of visitors a day.


I recommend you start with just 2 servers: one web server and one database server. Put as much ram on your DB server and more importantly make sure you can add more RAM later. Start with 16Gigs of ram and have room to expand it like 4 times just in case you will even need it. 16Gigs should be enough for start.

Make sure hard disks are fast. RAID 10 is the best choice.

Web server does not need to be super fast, 2 hard drives - one for system files, one where the program is. If you like logging then it's best to log to dedicated disk, so 3rd disk for that.

If you sending out lots of emails then you may need another server as email server. You may also use some type of messaging system like ActiveMQ to send mail jobs to mail server. LampCMS has EventDispatcher, so you can just write simple php class that listens to events that need to send out mass emails then use messaging like ActiveMQ (php has libraries for it) and then just post messages to ActiveMQ server. All these will be done after the page renders, so these things do not add to page load at all. You need to use fastcgi under control on php-fpm for that. I already said this like 100 times on this forum - use php-fpm and you'll have Java-like performance on php.





No comments:

Post a Comment