Checking what is eating your memory…. Part II

The experiment of yesterday was showing me only apache2 doing this; I was hoping the strace would show me the path to the offending code (as I am almost 100% sure it is PHP doing it). Instead it showed me an entire file full of mmap2 which are taking away memory. No paths as the strace only kicks in when the system is already dying, so too late.

So I had to make some code to check this further:


#!/usr/bin/perl

$maxmem=10;

`mkdir memstrace`;
`rm memstrace/*`;

%detected=();

open(F, ">mem.log");
while(1) {
@r=`ps auxwhww|awk '{print $4,$2,$11,$12,$13,$15}'|grep httpd-users|grep -v grep`;
foreach(@r) {
chomp;
/(.*?) (.*?) (.*)/;
if ($1>$maxmem and !$detected{$2}) {
print F "$_n";
$detected{$2} = 1;
}
next if -f "memstrace/$2";
if (!fork()) {
`strace -f -o memstrace/$2 -p $2`;
exit;
}
}
sleep 1;
}
close F;

Which should store all Apache syscalls including the offending and then log which one is offending when it becomes that.

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>