<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>2.3. Performance Tuning Introduction</title><link rel="stylesheet" href="./Common_Content/css/default.css" type="text/css"/><meta name="generator" content="publican"/><link rel="start" href="index.html" title="Community Services Infrastructure Standards"/><link rel="up" href="Apache-Standard-Introduction.html" title="Chapter 2. Introduction"/><link rel="prev" href="Apache-Standard-Introduction-Prerequisites.html" title="2.2. Prerequisites"/><link rel="next" href="Apache-Standard-Introduction-External_Sources_and_References.html" title="2.4. External Sources and References"/></head><body><p id="title"><a href="https://fedorahosted.org/publican"><strong>2.3. Performance Tuning Introduction</strong></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="Apache-Standard-Introduction-Prerequisites.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="Apache-Standard-Introduction-External_Sources_and_References.html"><strong>Next</strong></a></li></ul><div class="section" lang="en-US"><div class="titlepage"><div><div><h2 class="title" id="Apache-PerformanceTuning-Standard-Introduction-About">2.3. Performance Tuning Introduction</h2></div></div></div><p>
			Apache is the type of application that, during its lifetime as an application, can do the same thing millions of times over and over again. The result is that apache is an ideal application for tuning. When done properly tuning is as much science as it can be though its not perfect. This imperfection is where a skilled admin can make educated guesses. This art comes from things like not knowing when someone will /. you, or how many people will actually respond to the last mass mailing that was sent out.
		</p><p>
			This standard focuses not on getting every last drop out of a host until it crashes. Instead this standard focuses on setting values to a known max utilization. Once this utilization is hit, users will start to experience timeouts and slow connects or connection refused messages. Even at this fully utilized state the box will remain responsive. This has a few key benefits over letting the box get completely consumed and exiting on its own. The first of which is that administrators can still log in and examine the box while it is fully utilized allowing them to determine if something is configured incorrectly or if the number of resources assigned to this server are incorrect (for example, it needs more memory). The second advantage is that the box stays up and does continue to serve requests. The alternative is a box completely crashing turning all users away immediately. The theory being its better to have slow responses for a while then no responses for a while. It also gives the box better odds to recover from the load spike on its own.
		</p><div class="section" lang="en-US"><div class="titlepage"><div><div><h3 class="title" id="PerformanceTuning-httpd-settings">2.3.1. httpd config settings</h3></div></div></div><p>
				This section focuses on settings in <code class="code">/etc/httpd/conf/httpd.conf</code>.
			</p><div class="section" lang="en-US"><div class="titlepage"><div><div><h4 class="title" id="PerformanceTuning-httpd-MaxClientsServerLimits">2.3.1.1. MaxClients - ServerLimit</h4></div></div></div><p>
					<em class="glossterm">MaxClients</em>
					 - Maximum number of simultaneous requests that will be served
				</p><p>
					<em class="glossterm">ServerLimit</em>
					 - Upper limit on configurable number of processes
				</p><div class="section" lang="en-US"><div class="titlepage"><div><div><h5 class="title" id="PerformanceTuning-UsableRam">2.3.1.1.1. Usable Ram</h5></div></div></div><p>
						To determine the proper values for MaxClients and ServerLimit first you need to understand that we're trying to limit MaxClients and MaxServers based on some given amount of memory. According to the Apache docs “<span class="quote">The single biggest hardware issue affecting webserver performance is RAM.</span>” The easiest way to determine usable ram is to stop httpd, then find how much free memory there is on the host excluding buffers. This value can be determined by <code class="command">free | awk '/buffers\/cache/ { print $4 }'</code> This value is in kilobytes.
					</p></div><div class="section" lang="en-US"><div class="titlepage"><div><div><h5 class="title" id="PerformanceTuning-Buffers">2.3.1.1.2. Buffer Size</h5></div></div></div><p>
						We don't want apache to just take up whatever free memory there is because this would leave no room for buffers. Generally we'll leave 15% of UsableRam for buffers. <div class="equation" id="d0e309"><div class="equation-contents"><span class="mathphrase">UsableRam * .15</span></div><h6>Equation 2.1. BufferSize</h6></div><br class="equation-break"/>. 
						<div class="note"><h2>Note</h2><p>
								For many servers that don't do much disk IO you can leave less, like 10% (Like those servers reading and writing most of their information to a database. For servers that do a great deal of disk IO it is best to leave this a bit higher, at 20% or more.
							</p></div>
					</p></div><div class="section" lang="en-US"><div class="titlepage"><div><div><h5 class="title" id="PerformanceTuning-ApacheRam">2.3.1.1.3. Apache Ram</h5></div></div></div><p>
						ApacheRam is the amount of ram we're going to target for Apache use. <div class="equation" id="d0e326"><div class="equation-contents"><span class="mathphrase">UsableRam - BufferSize</span></div><h6>Equation 2.2. ApacheRam</h6></div><br class="equation-break"/>
					</p></div><div class="section" lang="en-US"><div class="titlepage"><div><div><h5 class="title" id="PerformanceTuning-httpd-AverageHttpdSize">2.3.1.1.4. Average Httpd Size</h5></div></div></div><p>
						Every httpd process takes up a certain amount of ram. Some of this memory is in shared memory, some of it is unique to each httpd process. To determine average httpd size we look at the size of each httpd process minus the shared memory size. To determine this size run <code class="command">echo $(($(for f in `pgrep httpd`; do awk '/Rss/ { rss+=$2 } /Shared/ { shared+=$2 } END { print rss-shared }' /proc/$f/smaps 2&gt; /dev/null; done | awk '{ s+=$1 } END { print s }') / $(pgrep httpd | wc -l)))</code>
					</p><div class="note"><h2>Note</h2><p>
							If stability is more important to you then performance. Add an additional 10% to this number. <div class="equation" id="d0e345"><div class="equation-contents"><span class="mathphrase">AverageHttpdSize * 1.1</span></div><h6>Equation 2.3. AverageHttpdSize</h6></div><br class="equation-break"/>
						</p></div></div><div class="section" lang="en-US"><div class="titlepage"><div><div><h5 class="title" id="PerformanceTuning-httpd-MaxClients">2.3.1.1.5. MaxClients</h5></div></div></div><p>
						To determine how high to set MaxClients in the actual httpd.conf file use the ApacheRam size and divide it by AverageHttpdSize. <div class="equation" id="d0e358"><div class="equation-contents"><span class="mathphrase">ApacheRam / AverageHttpdSize</span></div><h6>Equation 2.4. MaxClients</h6></div><br class="equation-break"/>
					</p></div><div class="section" lang="en-US"><div class="titlepage"><div><div><h5 class="title" id="PerformanceTuning-httpd-ServerLimit">2.3.1.1.6. ServerLimit</h5></div></div></div><p>
						ServerLimit is more like a hard limit to MaxClients. This should be about 1% higher then MaxClients. <div class="equation" id="d0e371"><div class="equation-contents"><span class="mathphrase">MaxClients * 1.1</span></div><h6>Equation 2.5. ServerLimit</h6></div><br class="equation-break"/>
					</p></div></div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="Apache-Standard-Introduction-Prerequisites.html"><strong>Prev</strong>2.2. Prerequisites</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="Apache-Standard-Introduction-External_Sources_and_References.html"><strong>Next</strong>2.4. External Sources and References</a></li></ul></body></html>