Other problem is memory usage. When a process is created, 80M is allocated for apache2. I think is too much.

Is that real or virtual memory? Honestly, it's not very much; more to the point, you should focus on fixing things that are causing problems, not just things that you "think" should be different.

If you want Apache processes to take up less memory, you should disable modules (as each one is more code that needs to be in memory). But if you need all the modules you've got enabled, then, well, that's that.

One approach I've used when administrating a memory-constrained machine was to move certain tasks out of Apache and into other servers, so I could tune them separately.

But a far simpler approach is to change

MaxClients           120

to something more reasonable for your workload:

If we consider the rewrite accesses and the main site traffic, we have about 70 requests per minute. Right now, we have 33 incoming connections.

I'll get back to that momentarily, but if you're only dealing with 33 concurrent requests, you don't need 120 workers!

MaxClients           40

And you should probably tune down MinSpareServers and MaxSpareServer to something like 5 and 10, respectively. There's no need to have 30 workers sitting around doing nothing.

Now, getting back to

If we consider the rewrite accesses and the main site traffic, we have about 70 requests per minute. Right now, we have 33 incoming connections.

If you've got 33 concurrent requests, but you're only doing 70 a minute, there are a couple of possibilities:

  1. Your requests are taking around 30 seconds each to serve!
  2. Your request rate isn't very stable, and most of the minute you're doing nothing.

If #1 is the case, I don't really know how to help - something is incredibly wrong, so wrong I don't even know where to tell you to start looking.

If it's #2, my guess is you're serving all your static assets (images, js, css, fonts) from your server. It's best to put these on a CDN, but if you really can't do that, you can set super-long cache times on them and turn Varnish back on. If you're using Apache processes with PHP and a whole host of other things just to serve static files, you're wasting resources - do that with something simpler!

My problem is that CPU (all cores) have a high load. Most of time, hitting between 90% and 100% load! The offending process is the apache2.

Is this a constant number, or only when you're serving requests?

How does disk I/O look (iostat -mhx 2)? What is MySQL doing (show processlist;)?


Your server is vastly overpowered for what you've described. This is good news, because it means you should be able to fix this problem.