5

We run Apache version 2.2.8-1ubuntu0.15 on our VPS instance of Ubuntu 8.04.4 LTS \n \l, as I determined by asking this question.

When I issue pgrep apache2, I get the following:

 2691
24517
25330
25669
25672
25795
25796
25809
25825
26401
26402

That's 11 seperate instances of apache2! Is this normal? If not, what should I do about it?

Iain Samuel McLean Elder
  • 1,152
  • 4
  • 13
  • 27

2 Answers2

5

Yes. Apache works like a traditional unix daemon, whereby:

  • Main program waits for an incoming request (blocks on a socket)
  • After receiving the request, the fork() system call is used, which causes the main process to clone itself
  • The main process then waits again for another request
  • The forked copy proceeds to handle the request, and terminates

Forking does consume time, so Apache preforks several instances in anticipation of handling multiple requests. This is totally configurable via /etc/apache2.conf. I can't think of the exact directives right now, but it's probably explained in the comments.

If you expect to handle sudden bursts of concurrrent HTTP requests, then it benefits you to have a lot of instances standing by to take them. The tradeoff is this consumes more memory.

2

If you're looking to lower this number use the MinSpareServers and MaxSpareServers directives:

http://httpd.apache.org/docs/2.2/mod/prefork.html

Rob Olmos
  • 2,220
  • 1
  • 15
  • 25
  • +1 for the documentation. Is this Apache's default behavior? If it is then I have no reason to change it for now. – Iain Samuel McLean Elder Sep 04 '10 at 04:06
  • Yes it is. If you look at the description box there's a term for "Default" where it specifies the default value (should you not specify it) for that directive. In this case it's 10 for Max and 5 for Min. Usually the distro's default config will specify them. – Rob Olmos Sep 04 '10 at 04:26