You will find there's php based web application and therefore are expecting a large spike in traffic by 50 percent days.

We're set on a typical Rackspace Light stack and can throw as numerous servers in internet marketing once we can however the application is very memory and db intensive so you will see some ceiling of max concurrent customers that we won't have the ability to exceed because of the short period of time we now have.

We've been trying to implement memcached but because of the character from the application it's showing hard to do effectively.

The visitors are only likely to last for a few hrs and our primary concern would be that the site does not crash which may bring sales to some halt.

What is the simplest method to display a mistake message that states "Sorry we're going through high-traffic, please repeat the process soon." Once the servers are going through overweight load?

In by doing this we're able to serve our proper web application after which once the request queue begins to fill only then do we can just serve the easy static friendly html traffic message.

I understand by using a naive approach it'll imply that many people who're nearly to purchase something can get the mistake message after which could go to the start of the procedure, which is not ideal, but because of the small amount of time-frame we simply require the site to not crash and prevent sales. How can we do that?

Any help could be greatly appreciated!

If by "heavy load" you mean CPU load this is really simple with sys_getloadavg(), a good example:

$load = sys_getloadavg()

$cores = intval(trim(spend_professional('grep physical /proc/cpuinfo  sort -u  wc -l')))

if ($load[] > $cores)

else if ($load[1] > $cores)

else if ($load[2] > $cores)

Based on your available memory and the amount of permitted PHP processes you may wanna just delay the response for a few milliseconds using usleep() rather than showing a "under heavy load" message. Remember that during sleep, the operation is still eating your memory and web server threads so you have to be careful with this particular - you are able to delay the response with respect to the load, i.e.:

if (($load[1] / $cores) >= 1)

   usleep($delay * 1000000)

The greater the burden, the greater the delay, this could give time for that CPU to meet up with everything.

If you are managing a distributed load balancer you may wanna keep these values in memcached, also storing the $cores variable in APC or similar will most likely provide you with a performance boost.

Should you meant other type of load (like customers or memory) the logic is comparable, all that you should be worried about is to buy the appropriate metric and store it, either on APC or memcached if you want distributed logic.

PS: ServerFault may well be a better spot to request this type of questions.