I've got something strange on my Apache2 server that is under Ubuntu Linux.
I've got two websites, one is directly handled by Apache2 through Passenger module (it's a ruby webapp), the other one is reverse proxied to another port to a Tomcat6 server.
Everything seems fine but Apache2 behaviour seems really greedy: with top
I see that it has at least 5-6 processes and they grow up to 13-14 when I make some requests for just these two servers.
Is it correct to have so many processes?
Should I configure it to be less greedy if there's no need? I was making comparisons with a similar configuration on a less powerful machine (512mb RAM vs 2gb RAM) and it seems that on this machine it keeps less processes open. Maybe Apache2 benchmarks the machine to understand how many resources to allocate?
Just for info both machines are actually virtualized under VMWare server
Thanks in advance
You should read through the Apache Documentation dealing with Multi-Processing Modules (MPMs). In a nutshell, this determines how Apache will handle multiple requests, and there's two main ways to do that: preforking (which is what it sounds like you're doing now) and threaded worker, which is often more efficient.
Prefork, as you said, creates and maintains a number of "spare" apache processes, and each process handles one client. When you get low on processes, Apache creates more. This can be slow and consume a lot of memory. How many processes are created can be tuned using the StartServers, MinSpareServers, and MaxSpareServers configuration directives.
Worker uses a single or a small number of processes, but creates multiple threads inside each process to handle each request. This can be much more efficient, but is not compatible with certain Apache modules which are not thread-safe (most notably PHP). So if you're using such modules, you'll want to consider switching to FastCGI.
From the Apache documentation:
And:
I switched from mod_php and mpm_prefork to FastCGI PHP and mpm_worker, and found a very large increase in performance, especially for static files (images, HTML files, etc). Your mileage may vary...