Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I host a PHP/MySQL application with Smarty caching on my server. It routinely gets short traffic spikes via tweets to thousands of followers. The traffic spike goes up to 6 hits /sec for upto 20-30 mins. And later reduces to less than a hit a second. During the spikes the response time gets really bad and goes upto more than two minutes for the page to be served.

How do I manage this? How do I find out what's the bottleneck on my server? I have a 1GB RAM server hosted on a cloud with CPU spiking. Should I buy more CPU or more RAM?

share|improve this question
    
When your server is slow, is the CPU maxed? Is the disk maxed? Are both? –  David Schwartz Feb 29 '12 at 7:03

3 Answers 3

The traffic spike goes up to 6 hits /sec for up to 20-30 mins

if you consider 6 hits per second a spike you need a reality check. I would consider 6 hits per second a zero load situation.

During the spikes the response time gets really bad and goes up to more than two minutes for the page to be served

Crappy programming or a very bad server, smaller than my mobile phone.

I have a 1GB RAM server hosted on a cloud with CPU spiking. Should I buy more CPU or more RAM?

Figure that out. I would basically start telling you that there is no way it should take minutes to respond on something that has 6 hits per second to start with - very unusual circumstances notwithstanding. Maybe you miss an index and force MySQL to do table scans all the time. I personally would be very concerned if I could not handle 6 requests per second on one core on a virtual machine, pretty much regardless how big it is. Or - brutally speaking: I would expect my phone to do that. Last time I did a larger website we considered 30ms to be the processing time limit. That would mean more than 30 requests per second per core.

Otherwise you need to find out - if your CPU really spikes then you need more CPU if RAM would be not sufficient and it would go to disc, then the CPU would not be fully busy. But again, this sounds like "my car only goes 30km/h, please tell me what to tune next" while the car SHOULD go a lot faster. This really smells a lot more like bad programming to start.

share|improve this answer

To try and answer your question, you need to get a better understanding of what is causing this slow-down. Here are a few things you could look at:

  • do you have slow mysql queries during the spikes? (have a look at your mysql slow log)

  • how many apache processes (if you are running apache) do you have running simultaneously during these spikes (see ps aux | grep apache | wc -l) and how does that compare to your maxclient setting?

  • how big is each apache process?

  • have your looked at top?

  • how much RAM is mysql using? (if you have phpmyadmin, look at your server status)

share|improve this answer
    
Thank you for that. Here's what I found: 1) I didn't find any slow mysql logged though it is enabled 2) There are about 50 httpd processes running (each about 32M VM and 14M Physical memory) but that command you said gives just 1 as output 3)26139 /opt/local/libexec/mysql mysql 45,328 27,180 0.1% - that's for mysql –  Aravind Apr 7 '12 at 18:19

More RAM, definitely! 6 hits/sec isn't all that much computationally. Even without knowing the specifics of your workload, the 1GB of memory is almost certainly your bottleneck.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.