top
rails batch
get process info that maybe leaked memory
pinfo=`ps aux --sort -rss| grep [r]uby | head -1 | tr -s ' ' | cut -d ' ' -f2,6`
echo $pinfo
compare and graceful kill
pid=`echo -n $pinfo | cut -d ' ' -f 1`
mem=`echo -n $pinfo | cut -d ' ' -f 2`
threshold=20000
if [ "$mem" -ge "$threshold" ];then
echo "Memory leaked!";
kill -s USR1 $pid;
fi
purge-memory-leak-process.sh
#!/bin/bash
# 200MiB
threshold=209715200
pinfo=`ps aux --sort -rss| grep [r]uby | head -1 | tr -s ' ' | cut -d ' ' -f2,6`
if test -z "$pinfo";then
echo "not found";
exit;
fi
pid=`echo -n $pinfo | cut -d ' ' -f 1`
mem=`echo -n $pinfo | cut -d ' ' -f 2`
if [ "$mem" -ge "$threshold" ];then
echo "[$pid]: Memory leaked!";
kill -s USR1 $pid;
fi