4 Answers
4

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.

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.