1

I have a small CGI application served via Apache2 and I would like to reduce the number of child processes that Apache2 maintains.

Here's the configuration (very basic) that I have for mpm_prefork.conf:

$ cat /etc/apache2/mods-enabled/mpm_prefork.conf 

<IfModule mpm_prefork_module>
    StartServers      1
</IfModule>

Here's what I found regarding StartServers:

The StartServers directive sets the number of child server processes created on startup.


Here's the number of processes that Apache is maintaining:

$ /etc/init.d/apache2 status
 apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─forking.conf
   Active: active (running) since mar 2018-03-06 10:16:36 CST; 16min ago
  Process: 9905 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 10117 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 9928 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/apache2.service
           ├─ 9942 /usr/sbin/apache2 -k start
           ├─10150 /usr/sbin/apache2 -k start
           ├─10151 /usr/sbin/apache2 -k start
           └─10152 /usr/sbin/apache2 -k start

mar 06 10:16:36 server001 apache2[9928]: Starting web server: apache2.
mar 06 10:16:36 server001 systemd[1]: Started LSB: Apache2 web server.
mar 06 10:26:12 server001 systemd[1]: Reloading LSB: Apache2 web server.
mar 06 10:26:12 server001 apache2[10050]: Reloading web server: apache2.
mar 06 10:26:12 server001 systemd[1]: Reloaded LSB: Apache2 web server.
mar 06 10:33:29 server001 systemd[1]: Reloading LSB: Apache2 web server.
mar 06 10:33:29 server001 apache2[10117]: Reloading web server: apache2.
mar 06 10:33:29 server001 systemd[1]: Reloaded LSB: Apache2 web server.


Every child process, is consuming something above 50Mb, and sincerely, for the type of application that I have, just one child would be enough.

$ ps -ylC apache2
S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
S     0  9942     1  0  80   0 25976 56792 -      ?        00:00:00 apache2
S    33 10150  9942  0  80   0  8416 36091 -      ?        00:00:00 apache2
S    33 10151  9942  0  80   0  8864 36097 -      ?        00:00:00 apache2
S    33 10152  9942  0  80   0  8716 56798 -      ?        00:00:00 apache2

Here are my questions:

  • Why I still have a main process + 3 child, instead of a main process + 1 child ?
  • What configuration should I use, in order to reduce the number of child processes ?


I'm a little bit new with Apache2. So please, be patient with my doubt.

ivanleoncz
  • 1,433
  • 4
  • 18
  • 32
  • 1
    Because there is also minspareservers maxspareservers maxrequestworkers. You would do well to check http://httpd.apache.org/docs/2.4/mod/prefork.html and http://httpd.apache.org/docs/2.4/mod/mpm_common.html . Also consider prefer may not be the most performant solution specially if you have load spikes from incoming requests, for which a threaded model mpm would be much more agile. – ezra-s Mar 07 '18 at 11:08
  • I try to use them, but no use. Could give a real answer, pointing the specific configuration? Indeed, the application is very small, and used by two persons, at maximum, so I'm not worried about load spikes. – ivanleoncz Mar 07 '18 at 15:39

1 Answers1

2

On your demand here is a setup you can use to limit the amount of processes in prefork to just 2:

Startservers 1
MinSpareServers 1
MaxSpareServers 2
MaxRequestWorkers 2
ServerLimit 2
MaxconnectionsPerChild 0
ezra-s
  • 2,215
  • 1
  • 7
  • 13