List memory usage per Unicorn worker
I have been using this snippet recently to show the amount of memory currently being consumed by each Unicorn worker. This is a convenient way of checking:
- The expected number of workers is being run
- The memory usage of workers is fairly uniform
- The average memory usage of Unicorn workers (if you are considering adding or removing workers)
Here’s the command:
ps -e -www -o pid,rss,command | grep -e '[u]nicorn_rails worker' | awk '{printf "%s %s\t%s mb\n",$3,$4,$2/1024}'
To break this down:
ps -e -www -o pid,rss,command
- list each process’s pid, memory usage in bytes, and the commandgrep -e '[u]nicorn_rails worker'
- filter the command list to those than mention Unicorn workersawk
- this just pretty-prints the list in the format ‘[command] [memory] mb`.