Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

After several nagios messages like "CRITICAL - load average: 135.12, 92.20, 44.09" and oom-killer, I checked the configuration again and again, with different settings, but no success.

The only work-around which seems to help on the ubuntu box, is this cleaner cronjob:

[ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete

Reading the oom-killer info, tells me about apache2 to be the bad (parent) process. There is only few traffic on this vserver and hardly any peaks.

lscpu

Architecture: x86_64

CPU op-mode(s): 32-bit, 64-bit

Byte Order: Little Endian

CPU(s): 1

free -m

Mem: 2003 835 1168 0 18 381

-/+ buffers/cache: 435 1568

Swap: 1019 129 890

apache2.conf mpm

<IfModule mpm_prefork_module>
    StartServers          2
    MinSpareServers       2
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   10000
</IfModule>
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    KeepAliveTimeout     15     
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          100     
    MaxRequestsPerChild 10000   
</IfModule>
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          100     
    MaxRequestsPerChild 10000
</IfModule>

Isn't there something like a mysql_tuner.sh for apache or a useful example for a similar vps?

THX

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You are over allocating on memory - OOM means "Out of memory" - the high load averages will be a result of the machine swapping.

You don't need a tuning script to know what appropriate settings to use. Launch Apache, then look at the RAM usage of a single thread. Typically, for a PHP app, expect around 30MB. Then, you can start to figure out how many threads you can actually run.

You'll probably find you are over allocating memory at an app level (PHP max memory or MySQL) rather than the number of Apache threads itself; it is just that, that is the app tipping the usage over the edge.

For the time being, be very conservative, then work your way up. So lower the settings to something like this:

StartServers          1
MinSpareServers       1
MaxSpareServers       10
MaxClients            15
MaxRequestsPerChild   1500

Then lower all your MySQL memory settings, or at the very least, the number of connections (to around ~15); and lower all your PHP max. memory settings.

Memory Usage Script

Here's a little script I wrote for memory usage, but bear in mind, it isn't going to properly factor in shared libs etc.

Just create a new file,

Eg. /root/memory_usage.sh

Then run with the application name,

Eg. /root/memory_usage.sh apache2 or /root/memory_usage.sh mysqld

#!/bin/bash

grandtotal=0

if [ $# -lt 1 ];then
  echo "$0: invalid option"
  echo "You are missing required arguments"
  echo "1 Application name or 'all', 2 2nd application name (optional)"
  exit 0
fi

if [[ "$1" == "all" ]]; then
  tot=0;for i in `ps -e -orss=`;do tot=$(( $tot + $i )); done;
  echo "Total " $(( $tot /4096 )) "MB"
  exit
fi

for app in $@; do
  echo -n $app
  ps u -p $(pidof $app) | awk 'NR > 1 {nm += $5} END {print " Total:  " nm/1024 " MB"}'
  apptotal=`ps -e -orss=,args= | grep "$app" | awk 'NR > 0 {nm += $1} END {print nm}'`
  echo "$app Total: " $(( $apptotal / 4096 )) "MB"
  grandtotal=$(( $apptotal + $grandtotal ))
done

if [ $# -gt 1 ];then
  echo "Grand total: " $(( $grandtotal / 4096 )) "MB"
fi
share|improve this answer
    
Thanks, I would like to try your tip. But dunno which one i have to set to the numbers for testing: mpm_prefork_module vs. mpm_worker_module vs. mpm_event_module –  ledy Jun 24 '12 at 17:40
1  
Well, PHP isn't multi-threaded, so I would hope you are using prefork ... run apache2 -V to verify –  Sonassi Jun 24 '12 at 17:46
    
thanks again for the fast reply. your memory check script is telling about 3GB for apache2 only - although that's not in use! nopaste.info/78e944cb9d.html –  ledy Jun 24 '12 at 17:57
    
Bear in mind what I wrote in my comment earlier, it will show shared memory/libs in the VSZ/RSS calculation. You are allocating a massive amount of RAM to MySQL - so do as I said. Lower number of threads on Apache, connections on MySQL (to a MAX of 15) and lower PHP max memory to a sensible value (~16MB) –  Sonassi Jun 24 '12 at 18:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.