I currently have a Linode 512 VPS with Ubuntu 10.04 LTS (32bit).

I recently opened my website which attracts a lot of users from social networks and I've been hitting some CPU limits lately.

I'm getting around 20k users per day, today I had to restart the apache and MySQL processes several times as the CPU usage was too high, I could barely type in the command.

I want to resize it, but I'm not sure if there is something that I can do that will help me solve it.

Coding-wise, I don't have anything to change, I'm currently running a minimal amount of queries to the SQL server (on localhost) and I've done everything I could to improve the code.

I'm running GZip and it's important to say that my main purpose of the site is to serve images.


I'm running GZip and it's important to say that my main purpose of the site is to serve images.

That right there may be your problem. Gzip will surely help with text-heavy content, as that compresses easily, however images are already compressed, and trying to compress them further with gzip is an exercise in futility. Turn off gzip and see if that brings your CPU load down.

If it doesn't, then the next step is likely that you should split off your database to a second linode 512. I would do this before re-sizing your current Linode. When you deploy the second machine, make sure it's in the same datacenter, but on a different host. That way Apache and MySQL won't be competing for disk IO. Also, keep in mind that you should use Linode's back-end private network for communications between the two servers.


today I had to restart the apache and mysql processes several times as the cpu usage was too high

Then you've not configured your server correctly. Ensuring you etain sufficient capacity to manage the server is essential. And on a webserver bad performance snowballs - so you've ended up with hundreds of people unable to use your system. Throwing hardware at the problem is a temporary solution - but you need to learn a lot more about how to tune and manage your server - far more than could be provided in an answer here.

However, yes there are probably some quick wins - but you've provided no useful information about how your server is configured nor the pattern of the workload. Taking a random guess, I'd suggest you have a look at content caching - particularly on proxies. Go read some of Mark Nottingham's online stuff.

You obviously have no idea what parts of your system are causing your problems - you need to start logging %D n your apache logs and analysing the data to work out where the performance problems are; hint: high CPU on a server providing only static content is very unusual - you might think that's where the load is coming from - but I doubt it.


I agree with symcbean. Getting some data on the actual cause of the problem would be a good first step, and caching can make lightweight servers stretch a very long way.

Take a look at Munin (and enable the MySQL plugins that aren't switched on by default) for the stats.

Beyond setting cache headers (and there's a Mark Nottingham article here: http://www.web-caching.com/mnot_tutorial/), Varnish can sit in front of Apache and cache static content on disk or in memory, reducing the load on Apache.

Others would argue that Lighttpd or Nginx would make good alternatives to Apache for static content.

If you want line by line setups for either Munin or Varnish on Ubuntu 10, let me know and I'll post them.


The best way to improve your code is ... that your code don't get executed.

try to use a web server with low memory use, lighttpd or nginx.

try that your app generate static content to be served, and regenerate the code when an update was done, this way your web server will do the best thing that can do, serve static content, check your headers in your html and images served.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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