Support
- Advanced Backup
- Client Side
- Cloud Enterprise
- ColdFusion
- Control Panel
- cPanel
- Customer Portal
- DNS Information
- Dedicated Servers
- DirectAdmin
- Domain Name
- dotDefender
- Dreamweaver
- FileCatalyst
- Front Page
- FTP
- General Information
- Hosted Exchange & SharePoint
- IIS6
- IIS7
- Juniper Netscreen Firewalls
- Linux
- Bind Multiple IP Addresses to a Single Network Interface Card (NIC)
- Clear Memory Cache on Linux Server
- Set the time on a Linux server
- Check Disk Usage in Linux
- Add Custom SpamAssassin Rules
- Install OSSEC on a Linux server
- Define the Default Document Order for a Shared Linux Server
- Administer a Website Using Webmin
- Use a Redirect Script in PHP
- Upgrade PHP on a Linux Server
- Install phpMyAdmin on a Linux server
- Add a Redirect Script to Your .htaccess File
- Install the Mumble VoIP Server to Redhat or CentOS
- Add PHP Extensions with No Control Panel or Plesk
- How To Update Linux Packages Using Webmin
- Evaluate Disk Usage on Linux Plesk Server
- How to monitor Bandwidth with VNstat
- Bind IPs to a server in Linux
- Using the Htaccess File to Block IP Access
- Using The Htaccess File for PHP Directives
- Search for a file via SSH
- Install Tomcat on a Linux Server
- Install the Railo CFML Server in Linux
- Tuning the Apache Prefork MPM
- Adding FTP Users For VSFTP
- Installing htop
- Enable Apache mod_status
- Evaluate Disk Usage on Linux Cpanel Server
- Locate Newly Created Files in Linux
- Configure Keep Alives on SSH Server in Linux
- Adjusting the Amount of Swap
- How to Disable IPv6 For Redhat and Centos
- Enable and Use the Apache Info Module
- Install NCDU on a Linux Server
- Manage the Qmail queue with qmHandle
- Retaining File Permissions While Using SCP
- How To Compress And Uncompress Files
- Installing Freetds For Linux
- Create Search Engine Friendly URLs with mod_rewrite
- Adding Users To A Usergroup
- Installing Vim
- Use TCP Variable tcp_syncookies to prevent "syn flood attack"
- How To Limit Process CPU Usage
- Install and Configure the Cherokee Web Server on Linux
- Installing Python 3 on CentOS/Redhat 5.x From Source
- Configure Syntax Highlighting in Vim
- Install and Configure the Nginx Web Server on Linux
- Set Hostname
- Using Tmux
- MySQL Slow Query Logging
- Using the Linux Uptime Command
- Using sar to Monitor System Performance
- Compile Software On Linux
- Using the Linux Man Command
- Mounting NFS Shares
- Move and Copy Files within Linux
- Configure NFS Server Shares
- Software Management with RPM and Yum
- Update the Webmin Control Panel
- Viewing Live Bandwidth with iftop
- Using GNU Screen
- Sshwindows
- Sshmac
- Directorystructure
- Errorcheck
- vi Text Editor
- Find Heaviest Email Users of Postfix MTA's Deferred Spool
- Common Rewrite Rules for .htaccess
- Turn on directory listing in Linux
- Redirect non-www URLs to www URLs using a .htaccess file
- Force Visitor Browser to use SSL in Apache
- Apache Error Logging
- Password-less Login Through SSH Linux To Linux
- Log SSH Sessions with Putty
- SSH Server on Alternative Port
- SSH Server as Secure SOCKS Proxy
- Install the PHP Process Manager (php-fpm)
- Configure Apache to Use PHP-FPM
- Configure Nginx to Use PHP-FPM
- Cgiscripts
- Htaccess
- Linux Faq
- Phpmail
- Phpmailer
- Phpsqlinjection
- Phpversion
- Sendmail
- Add a Redirect Script to your Ruby on Rails Application
- Use a CGI PERL Redirect Script
- List Server
- MIVA Merchant
- MySQL
- Patching / Server Updates
- phpMyAdmin
- Plesk
- Policies and Procedures
- Premium Spam Filtering
- Programming
- Ruby on Rails
- Search Engine Submission
- SharePoint 3
- SharePoint 2010
- SiteDesigner
- SmarterMail 3
- SmarterMail 4
- SmarterMail 5
- SmarterMail 6
- SmarterMail 7
- SmarterStats
- SmarterTrack
- SQL Server
- Secure Socket Layer (SSL)
- Uploading Your Website
- Video Tutorials
- Windows Server 2003
- Windows Server 2008
- Web Design
- WordPress
- Advanced Monitoring
- MediaWiki
- Enkompass
- Microsoft Outlook 2010
- Android
- Outlook Web Access
- Critical Availability Service
- NAS Data Transfer
- Customer Portal Demos
- Joomla
- Moodle
- Cloud Dedicated
- Gallery CMS
- phpBB
- Standard Monitoring
- Righteous Restore
- NAS (Network Attached Storage)
- Networking
- SmarterMail 8
- PCI Security Scan
- LinkTiger
- Windows Cloud VPS
- Linux Cloud VPS
- Linux VPS
- Windows VPS
- Hyper V
- ENSIM
- Alert Logic
- Webmin
- e107
- Vbulletin
- VPN
- Visual Vault
- Mozilla Thunderbird
- PyroCMS
- Active Directory
- Vmware Related
- Drupal
Tuning the Apache Prefork MPM
Apache uses a set of values called the Prefork MPM to determine how many servers it will utilize and how many threads each server can process. Out of the box all Apache installations use the same values regardless of whether your server has 512Mb of RAM or 8Gb of RAM. It is important that as the server administrator you configure these values to work with your server load.
The Apache Prefork MPM can be found in the Apache configuration file; usually /etc/httpd/conf/httpd.conf. The default values are...
<IfModule prefork.c>
StartServers 2
MinSpareServers 3
MaxSpareServers 3
ServerLimit 75
MaxClients 75
MaxRequestsPerChild 1000
</IfModule>
Each Directive taken from "http://httpd.apache.org/docs/trunk/mod/mpm_common.html" is detailed below.
- - - - - - - - - - - -
The StartServers directive sets the number of child server processes created on startup. As the number of processes is dynamically controlled depending on the load there is usually little reason to adjust this parameter.
- - - - - - - - - - - -
The MinSpareServers directive sets the desired minimum number of idle child server processes. An idle process is one which is not handling a request. If there are fewer than MinSpareServers idle then the parent process creates new children until satisfies the MinSpareServers setting.
- - - - - - - - - - - -
The MaxSpareServers directive sets the desired maximum number of idle child server processes. An idle process is one which is not handling a request. If there are more than MaxSpareServers idle, then the parent process will kill off the excess processes.
- - - - - - - - - - - -
The ServerLimit directive is only used if you need to set MaxClients higher than 256 (default). Do not set the value of this directive any higher than what you might want to set MaxClients to.
- - - - - - - - - - - -
The MaxClients directive sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxClients limit will normally be queued, up to a number based on the ListenBacklog directive. Once a child process is freed at the end of a different request, the connection will then be serviced.
For non-threaded servers (i.e., prefork), MaxClients translates into the maximum number of child processes that will be launched to serve requests. The default value is 256; to increase it, you must also raise ServerLimit.
- - - - - - - - - - - -
The MaxConnectionsPerChild directive sets the limit on the number of connections that an individual child server process will handle. After MaxConnectionsPerChild connections, the child process will die. If MaxConnectionsPerChild is 0, then the process will never expire.
Setting MaxConnectionsPerChild to a non-zero value limits the amount of memory that process can consume by (accidental) memory leakage.
- - - - - - - - - - - -
The single most important directive is MaxClients as this determines the amount of Apache child processes that will be launched to server requests. A simple calculation for MaxClients would be:
(Total Memory - Critical Services Memory) / Size Per Apache process
I define Critical Services as services such as mySQL, Plesk, Cpanel; any service that is required for proper operation of your server.
I've used the following commands via shell to determine values for Total Memory, OS Memory, MySQL Memory, and Apache Process Size
TOTAL MEMORY
[root@vps httpd]# free -m
total used free shared buffers cached
Mem: 1002 599 402 0 28 337
-/+ buffers/cache: 233 769
Swap: 2047 124 1922
MYSQL MEMORY
[root@vps httpd]# ps aux | grep 'mysql' | awk '{print $6}'
408
21440
704
APACHE PROCESS SIZE
[root@vps httpd]# ps aux | grep 'httpd' | awk '{print $6}'
22468
11552
41492
40868
41120
41696
39488
41704
15552
16076
16084
728
In this case the server has 1002Mb of memory allocated, xx used by the OS itself, 21Mb used by mySQL, and each Apache thread averages about 30Mb.
MaxClients = (1002 - 21) / 30 therefore MaxClients = 32.7
The next important aspect is MaxConnectionsPerChild as this is the amount of threads that will be processed before the child is recycled.
A good calculation for MaxConnectionsPerChild would be:
(total amount of daily requests / total number of daily processes)
Determining these values is a bit more complex as it requires some type of statistics package or thorough knowledge of interpreting Apache access logs.
As this does not adversely effect memory usage, only cpu time to cycle the process if you are unable to determine this information the standard 1000 should be used.
Thus a good configuration for this server would be
<IfModule prefork.c>
StartServers 2
MinSpareServers 3
MaxSpareServers 3
ServerLimit 30
MaxClients 30
MaxRequestsPerChild 1000
</IfModule>
Be sure once you've saved the file to perform a configuration test before restarting Apache.
[root@vps httpd]# service httpd configtest
Syntax OK
[root@vps httpd]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]


