BleakHouse tracking a simple action, using the pure-Ruby memlogger:
ObjectSpace is quantum—you can’t interact with it without changing it. This makes it useless as a profiler. I didn’t realize how useless it was until I wrote BleakHouse, though. Until then, I had guessed that other implementations (such as Rublique) were just poorly done. But even after eliminating leaks in those…
Anyway. The new hotness, BleakHouse 5:
Bonus: it charts memory usage now (swap, real, and combined). And it’s faster.
More gems required than before:
You need to build a patched Ruby binary, unfortunately. I borrowed Eric Hodel’s patch from
mem_inspect and wrote a Rake task to handle it all for you. To build, just install the plugin one way or another, and then from the
bleak_house folder, run:
sudo rake ruby:build
It will give you a new Ruby 1.8.6 binary called
ruby-bleak-house alongside your existing one.
(Build process tested on OS X. Should be fine on Linux. Won’t work on Windows, but maybe you can hack it out. You should be profiling in an environment that approximates your deployment environment, though, so a win32 version doesn’t really make sense. Unless you deploy on win32. You probably also chew nails for fun.)
The options have changed a bit. Start your server with:
RAILS_ENV=production BLEAK_HOUSE=true ruby-bleak-house script/server
Fire requests. Bonus points if you do it in a repeatable way. Even Monte Carlo methods are more consistent than by-hand. Consider using
RAILS_ENV=production SMOOTHNESS=2 rake bleak_house:analyze
The smoothness setting averages series of frames. You can’t set it lower than 2. There’s no upper limit. It’s most useful when you aren’t hitting the same action every request. (It would be nice to use a Gaussian kernel instead of an average, but…)
Check the source if you want to see some interesting things. You can use the memlogger separately, too—you don’t have to profile a Rails app.
And please report problems on the forum.
Thanks much to Ryan Davis for RubyInline, Eric Hodel for
mem_inspect, Evan Phoenix for telling me about
mem_inspect, and David Goodlad for helping with the C extension.