Archive for November 14th, 2008

Pulling it all together.

In Part 1

I covered the use of pmap to provide an insight into the memory footprint of the apache service.

In Part 2

I covered a list modules that are typically enabled in a standard httpd/apache setup, and listed which modules I was disabling to reduce the memory foot print.

After improving the appmem script in Part 4 of the linux sysadmin script I updated part 3 of this series with the new memory foot print figures.

Summary aside, now we have reduced the memory footprint of your apache installation lets go onto actually making the most of your new found memory excess ..’potential’ max clients.

As stated in part 3 of this series, I am assuming the server you are making these configuration changes is a dedicated apache server.

However you also need to be aware of your CGI programs such as PHP, if you are to configure PHP with a maximum memory of 32MB, you must be aware that there is the potential for PHP to try to use this much memory on each allocation, this is where “optimizing PHP gor high load sites” comes into play, a furture series I plan to write, for the time being however I am only covering the configuration of apache.

Your httpd.conf should have the following entries (or similar).


# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves

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

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves

StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0


[buzz@buzz_srv ~]httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c

As can be seen above in my installation the part of the config I am interested in is prefork.c.

Now with my theorehtical max clients in part 3 hitting 800.5, lets first go for a safer figure, say 60%



StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 480
MaxClients 480
MaxRequestsPerChild 4000

From here use the script in part 1 of the Linux sysadmin script, to monitor your active http connections, and ‘tweak’ your configuration accordingly.

Remember you must only set the MaxClients and ServerLimit to a value you can safely contain in ram, swapping out to disk will cause a major slow down.

Tags: ,

Comments No Comments »

In part 4, I am going to cover more of an improvement than anything else to part 3

Part 3 itself is not incorrect, it correctly takes a memory footprint for each process running, the same as VIRT in top …

However in processes such as APACHE the VIRT memory is the size of all shared libraries, as correctly shown by pmap …

So what does this mean realy?

The memory usage is infact the following VIRT + RSS, where RSS is the resident set size, the RSS is a representation of the memory in use by the PID, and VIRT is shared between the child processes.


[buzz@buzz_srv ~]# ps aux | grep httpd | grep -v ‘grep’
root 16378 0.0 0.1 148640 3024 ? Ss Nov13 0:00 /usr/sbin/httpd
apache 20088 0.0 0.1 148640 3304 ? S Nov13 0:00 /usr/sbin/httpd
apache 20101 0.0 0.1 148640 3304 ? S Nov13 0:00 /usr/sbin/httpd
apache 20756 0.0 0.1 148640 3312 ? S Nov13 0:00 /usr/sbin/httpd
apache 20759 0.0 0.1 148640 3300 ? S Nov13 0:00 /usr/sbin/httpd
apache 20790 0.0 0.1 148640 3284 ? S Nov13 0:00 /usr/sbin/httpd
apache 20792 0.0 0.1 148640 3312 ? S Nov13 0:00 /usr/sbin/httpd
apache 20798 0.0 0.1 148640 3308 ? S Nov13 0:00 /usr/sbin/httpd
apache 20804 0.0 0.1 148640 3308 ? S Nov13 0:00 /usr/sbin/httpd
apache 20886 0.0 0.1 148640 3304 ? S Nov13 0:00 /usr/sbin/httpd
apache 20906 0.0 0.1 148640 3300 ? S Nov13 0:00 /usr/sbin/httpd
apache 20907 0.0 0.1 148640 3308 ? S Nov13 0:00 /usr/sbin/httpd
apache 20912 0.0 0.1 148640 3304 ? S Nov13 0:00 /usr/sbin/httpd
apache 20915 0.0 0.1 148640 3312 ? S Nov13 0:00 /usr/sbin/httpd
apache 20959 0.0 0.1 148640 3304 ? S Nov13 0:00 /usr/sbin/httpd
apache 20969 0.0 0.1 148640 3300 ? S Nov13 0:00 /usr/sbin/httpd
apache 20994 0.0 0.1 148640 3320 ? S Nov13 0:00 /usr/sbin/httpd
apache 20995 0.0 0.1 148640 3288 ? S Nov13 0:00 /usr/sbin/httpd
apache 20996 0.0 0.1 148640 3320 ? S Nov13 0:00 /usr/sbin/httpd
apache 20997 0.0 0.1 148640 3320 ? S Nov13 0:00 /usr/sbin/httpd
apache 20999 0.0 0.1 148640 3296 ? S Nov13 0:00 /usr/sbin/httpd

As can be seen above the ‘VIRT’ does not change between the child processes, where as the RSS does dependant on what the thread is doing at that time.

So below is an improved appmem function to allow for this:


function appmem {
if [ -z "$1" ]; then
echo “Usage: sysadmin appmem app_name i.e. (sysadmin appmem apache)”;
else
RRES=(`ps aux | grep “$1″ | grep -v ‘grep’ | grep -v “$0″ | awk ‘{print $6}’`);
VRES=(`ps aux | grep “$1″ | grep -v ‘grep’ | grep -v “$0″ | awk ‘{print $5}’`);
COUNT=0;
VMEM=0;
RMEM=0;
for RSS in ${RRES[@]}
do
RMEM=$(($RSS+$RMEM));
done;
for VIRT in ${VRES[@]}
do
VMEM=$(($VIRT+$VMEM));
COUNT=$(($COUNT+1));
done;
VMEM=$(($VMEM/$COUNT));
VMEM=$(($VMEM/1024));
RMEM=$(($RMEM/1024));
echo -e “$YELLOW —– MEMORY USAGE REPORT FOR ‘$1′ —– $CLEAR”;
echo “PID Count: $COUNT”;
echo “Shared Mem usage: $VMEM MB”;
echo “Total Resident Set Size: $RMEM MB”;
echo “Mem/PID: $(($RMEM/$COUNT)) MB”;
fi
}

Example output:


----- MEMORY USAGE REPORT FOR 'httpd' -----
PID Count: 41
Shared Mem usage: 140 MB
Total Resident Set Site: 95 MB
Mem/PID: 2 MB

Tags: ,

Comments 2 Comments »