0

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?

1
  • When your server is slow, is the CPU maxed? Is the disk maxed? Are both? Feb 29, 2012 at 7:03

3 Answers 3

6

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.

3

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)

1
  • 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
    – Man_Pat
    Apr 7, 2012 at 18:19
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .