Apache Performance Tuning: Swap Memory
Before we get into the details of Apache tuning, we need to understand what happens when a VPS server or Dedicated server goes unresponsive due to a poorly optimized configuration.
An over-tuned server is one that is configured to allow more simultaneous requests (ServerLimit) than the server’s hardware can manage. Servers set in this manner have a tipping point, and once reached, the server will become stuck in a perpetual swapping scenario. Meaning the Kernel is stuck rapidly reading and writing data to and from the system swap file.
Swap files have read/write access speeds vastly slower than standard memory space. The swap files' latency can cause a bottleneck on the server as the Kernel attempts to read and write data faster than is physically possible or more commonly known as thrashing. If not caught immediately, thrashing spirals the system out of control leading to a system crash.
If trashing is left running for too long, it has the potential of physically harming the hard drive itself by simulating decades of read/write activity over a short period. When optimizing Apache, we must be cautious not to create a thrashing scenario. We can accomplish this by calculating the thrashing point of the server based on several factors.
Pre-Flight Check
This article covers all Apache-based servers including but is not limited to, both traditional Dedicated servers and Managed Cloud servers running a variety of Linux distributions. We will include the primary locations where stored Apache configurations on the following Liquid Web system types:
Estimate the Thrashing Point
Calculating the estimated thrashing point or ServerLimit of a server uses a simple equation:

- buff/cache: The total memory used by the Kernel for buffers and cache.
- Reserved: The amount of memory reserved for non-Apache processes.
- Available: The difference between buff/cache and Reserved memory.
- Avg.Apache: The average of all running Apache children during peak operational hours.
The thrashing point value is equal to the number Apache children the server can run; this applies to either threaded or non-thread children. When the number of children running in memory meets the calculated thrashing point, the server will begin to topple. The following example walks through a standard Liquid Web Fully Managed cPanel server to illustrate gathering the necessary details to calculate a system’s estimated thrashing point.
Buff/Cache Memory
On modern Linux systems, the buffer/cache can be derived using the /proc/meminfo file by adding the Buffers, Cached and Slab statistics. Using the free command, we can quickly grab this information, as in the example below:
free
Output:

Don’t be fooled by the column labeled “available.” We are solely looking at the memory we can reappropriate, which is the buff/cache column (708436).
Reserved Memory
Reserved memory is a portion of memory held for other services aside from Apache. Some of the biggest contenders for additional memory outside of Apache are MySQL, Tomcat, Memcache, Varnish, and Nginx. It is necessary to examine these services configs to determine a valid reserved memory. These configs are outside the purview of this article. However, MySQL is the most commonly encountered service running with Apache. You can find tools online to help analyze and configure MySQL separate from this article.
- A standard cPanel server runs several services along with Apache and MySQL. A server with these services run on the heavier side, needing 25% reserved for non-Apache services.
- A pure Apache web node in a high capacity load balanced configuration does not need to reserve any additional ram for other services.
Average Apache Memory
Finding the average size of Apache processes is relatively simple using the ps command to list the RSS (Resident Set Size) of all running httpd processes. Note: some distributions use “apache” instead of “httpd” for process name.
This example uses a short awk script to print out the average instead of listing the sizes.
ps o rss= -C httpd|awk '{n+=$1}END{print n/NR}'
Output:
22200.6
This example is easy to average manually, but larger servers will require more calculation.
ps o rss -C httpd
Output:
RSS
5092
27940
28196
27572
Calculate the Thrashing Point
Once collected divided the Available memory by Avg. Apache, rounding down to the nearest whole number. Available memory is the buff/cache memory minus the Reserved memory. Below is a summary of the calculation process in table form.

Conservative estimates are provided below for various memory configurations. These estimates can be used as a starting configuration but will require additional follow up performance assessments during peak hours to adjust directives by the servers.

Conclusion
Determining the best optimization point for Apache can save the server from downtime, wasted sales, and lost clients. Regulating available resources is a critical component to ensure your service stays up and running at optimal speed,
Our experienced technicians and systems administrators are always available to show you how you can take advantage of these techniques today!
We are available 24 hours a day, 7 days a week 365 days a year, via our ticketing systems at support@liquidweb.com, by phone (at 800-580-4986) or via a LiveChat or whatever method you prefer.
Because we pride ourselves on being The Most Helpful Humans In Hosting™, we work hard so you don't have to!
Related Articles:
- How to Use Disk Quotas in Dedicated Linux Servers With cPanel
- How to Use Disk Quotas in Dedicated Linux Servers with Plesk
- Remove a MySQL User on Linux via Command Line
- Remove Permissions for a MySQL User on Linux via Command Line
- Grant Permissions to a MySQL User on Linux via Command Line
- Using MySQL Command Line to Create a User

About the Author: Justin Palmer
Justin Palmer is a professional application developer with Liquid Web
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Edit the PHP Memory for Your WordPress Site via WP Toolkit
Read ArticleWhat is CGI-Bin and What Does it Do?
Read ArticleTop 10 Password Security Standards
Read ArticleTop 10 Password Security Standards
Read ArticleHow to Use the WP Toolkit to Secure and Update WordPress
Read Article