Apache workers

From Training Material
Revision as of 17:47, 24 November 2014 by Cesar Chew (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
title
Apache workers
author
Sam Bashton (NobleProg Ltd)

Apache worker model ⌘

  • Apache can function using different models
  • Most common - prefork

Apache prefork ⌘

  • One central Apache process to accept incoming connections, read configuration etc
  • Multiple child processes to serve requests
  • Each child can serve only one request at a time

Apache prefork settings ⌘

```
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
```

Tuning Apache prefork ⌘

  • StartServers
  • Number of Apache processes to create on first start
  • MinSpareServers
  • Minimum number of spare Apache processes that should be available at any time. If less spare workers than this are available, Apache will start more
  • MaxSpareServers
  • Maximum number of spare workers.If more than this are available, Apache will kill them off at a rate of 1/second to bring it below this.

Tuning Apache prefork ⌘

  • Default EL5 config has a maximum of 256 child processes
  • This means maximum 256 concurrent requests
  • In reality, 256 may well be too high
  • When using PHP, Apache processes are often 30MB+
  • 30 * 256 = 7680MB of RAM required, just for workers
  • Under these conditions, 256 MaxClients suitable only for machines with at 8GB RAM

Sizing MaxClients ⌘

  • Tool ps_mem.py can be used
  • Set MaxClients too high, and you'll start swapping

What are the workers doing? ⌘

  • Apache module `mod_status` shows this data
  • Module is loaded by default but not enabled
  • Uncomment the section in /etc/httpd/conf/httpd.conf to enable
  • Change `.example.com` to `127.0.0.1`
  • Once enabled, run `service httpd fullstatus` to see data

Exercise ⌘

  • Enable mod_status and find the status of each worker
  • How much memory is each httpd process using on your VM?
  • What is a suitable value for MaxClients on this VM based on the above?