CARVIEW |
GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009! [ hide ]
Every repository with this icon (

Every repository with this icon (

Description: | Adds in proccess id and memory usages in your rails logs, great for tracking down memory leaks |
Clone URL: |
git://github.com/binarylogic/memory_usage_logger.git
Give this clone URL to anyone.
git clone git://github.com/binarylogic/memory_usage_logger.git
|
name | age | message | |
---|---|---|---|
![]() |
MIT-LICENSE | Thu Sep 11 09:59:59 -0700 2008 | Initial commit [binarylogic] |
![]() |
README.mdown | Sun Nov 23 22:33:33 -0800 2008 | Updated readme [binarylogic] |
![]() |
init.rb | Thu Sep 11 09:59:59 -0700 2008 | Initial commit [binarylogic] |
![]() |
lib/ | Tue Oct 21 15:41:49 -0700 2008 | Added line by line memory logging [binarylogic] |
Memory usage logger
This is linux specific. The following command retrieves the memory:
memoryusage = ps -o rss= -p #{$$}
.toi
The reason I created this was to help track down a memory leak. It worked very well because it adds the process id and memory usage in with EVERY single line logged and at the end of each rails request. By every line, I mean every line in your log will end with ” (mem #{memoryusage})”.
This way, if you have a cluster, you can monitor each process and scroll through your logs and watch the memory. If it suddenly starts to jump you can look at the request and at least you have a starting point. You can checkout the code for that specific controller action and try to narrow it down.
Tips
Open up your log in a program that is made to read large files, NOT textmate. The console on the mac is a great program for this. To track a process id just do a “find next” with that process id. Watch the memory as you do this, if you have a true leak it will either gradually increase and never stop, or jump all at once. This will help you pin point the type of requests increasing your memory.
A great tool for hammering your server to find the memory leak yourself is the apache benchmarking tool. It should come pre-installed on your mac. Do something like:
ab -kc 10 -t 30 https://127.0.0.1:3000/
The above will create 10 threads to hammer your server for 30 seconds as fast as they can. This will go crazy, so be careful. If you have a bad memory leak this will consume your memory in no time.
Installation
class Applicationcontroller include MemoryUsageLogger end
Copyright (c) 2008 Ben Johnson of Binary Logic, released under the MIT license