• Stars
    star
    189
  • Rank 204,649 (Top 5 %)
  • Language
    Ruby
  • License
    Academic Free Lic...
  • Created over 16 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby library for finding memory leaks

BleakHouse

A library for finding memory leaks.

DEPRECATED¶ ↑

Please use Kiji instead.

License¶ ↑

Copyright 2007, 2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file. Portions copyright 2006 Eric Hodel and used with permission. See the included LICENSE_BSD file.

The public certificate for this gem is here.

If you use this software, please make a donation, or recommend Evan at Working with Rails.

Features¶ ↑

  • leak-proof C instrumentation

  • minimal impact on runtime performance

  • fast analysis step

  • tracks all objects allocated on the heap, including internal types like T_NODE

  • easy integration into any program, not just Rails

Requirements¶ ↑

  • A unix-like operating system

  • Ruby 1.8.7

Usage¶ ↑

Installation¶ ↑

Install the gem:

sudo gem install bleak_house

The installation takes a long time because it compiles a patched Ruby 1.8.7 binary for you. It is installed as ruby-bleak-house alongside your regular ruby binary.

Please see the forum ( github.com/fauna/bleak_house/issues ) if you have installation problems.

Usage¶ ↑

We will profile a Rails app as an example. Note that BleakHouse works equally well in any Ruby program.

First, to setup the app for profiling, add the following at the bottom of config/environment.rb:

require 'bleak_house' if ENV['BLEAK_HOUSE']

Then, to engage the logger (possibly in a live deployment situation), start a server instance as so:

RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house ./script/server

Look for the message:

** Bleakhouse: installed

Exercise your app. After a couple hundred requests, hit CTRL-C. The server will stop and BleakHouse will produce a dumpfile in /tmp:

** BleakHouse: working...
** BleakHouse: complete
** Bleakhouse: run 'bleak /tmp/bleak.5979.000.dump' to analyze.

To analyze it, just run the listed command. The top 20 leakiest lines will be listed:

191691 total objects
Final heap size 191691 filled, 220961 free
Displaying top 20 most common line/class pairs
89513 __null__:__null__:__node__
41438 __null__:__null__:String
2348 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:Array
1508 /opt/local//lib/ruby/gems/1.8/specifications/gettext-1.90.0.gemspec:14:String
1021 /opt/local//lib/ruby/gems/1.8/specifications/heel-0.2.0.gemspec:14:String
 951 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:111:String
 935 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:String
 834 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:146:Array
...

You can pass an integer as the second parameter to bleak if you want to see more lines than the default.

The underscored types are special Ruby internal structs, but can be real leaks just as easily as fullblown classes.

Extras¶ ↑

Injecting a signal¶ ↑

You can send SIGUSR2 to a BleakHouse-instrumented program to snag a dump at any time. Once the dump completes, the program will continue to run. Dumps are named based on the host process id, and sequential dumps are numbered in ascending order.

Tips¶ ↑

Do not try to detect Rails leaks in development mode. Make a separate benchmark environment if you need to, and make sure all your production caching is turned on.

It is normal to see lots of null:null references, especially for nodes. Using eval() too much can be a cause of node leaks. You can sometimes track eval() by using sourceline macros in your code:

eval("CODE", nil, __FILE__, __LINE__)

You may get library require errors if you install ruby-bleak-house 1.8.7 alongside a different verson of Ruby. You could try to patch your local version of Ruby instead, or you can get ruby-bleak-house to lie about its version. Just make sure that the bleak-house library is the first thing required (even before Rubygems):

ruby-bleak-house -I `ruby -e 'puts \`gem which bleak_house\`.split("\n")[1][0..-16]'` -rbleak_house

It is not recommended that you use ruby-bleak-house as your production Ruby binary, since it will be slightly slower and use slightly more memory. It is unlikely, however, to affect stability.

If BleakHouse doesn’t report any heap growth but you still have memory growth, you might have a broken C extension, or have encounted a real leak in the interpreter. Try using Valgrind instead.

Methods¶ ↑

The easiest way to fix a leak is to make it repeatable.

First, write a script that exercises your app in a deterministic way. Run it for a small number of loops; then run bleak. Then run it for a larger number of loops, and run bleak again. The lines that grow significantly between runs are your leaks for that codepath.

Now, look at those lines in the source and try to figure out what references them. Where do the return values go? Add some breakpoints or output backtraces to STDERR as you go. Eventually you should find a point where it is relatively clear that a reference is getting maintained.

Try to remove that reference, run your script again, and see if the object counts have dropped.

Reporting problems¶ ↑

The support forum is here.

Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.

Further resources¶ ↑

More Repositories

1

has_many_polymorphs

An ActiveRecord plugin for self-referential and double-sided polymorphic associations.
Ruby
202
star
2

ultrasphinx

Ruby on Rails configurator and client to the Sphinx full text search engine
Ruby
170
star
3

mongrel

Mongrel
Ruby
144
star
4

peep

A heap inspector for live memcached instances.
Ruby
104
star
5

echoe

A Rubygems packaging tool that provides Rake tasks for documentation, extension compiling, testing, and deployment
Ruby
82
star
6

interlock

A Rails plugin for maintainable and high-efficiency caching
Ruby
75
star
7

ccsv

A pure-C CSV parser for Ruby
Ruby
64
star
8

raspell

A Ruby binding for the Aspell spelling checker
C
59
star
9

sweeper

A Ruby script to automatically tag your music collection with metadata from Last.fm
Ruby
32
star
10

thrift-rb

Ruby bindings for Thrift, with patches.
Ruby
18
star
11

allison

A modern, pretty RDoc template
Ruby
11
star
12

sinatra-jar

Sample monolithic dependency-free Sinatra JAR
Ruby
11
star
13

heroku-hello-world-tests

Ruby
9
star
14

kirby

A super-clean IRC bot with sandboxed Ruby evaluation, repository watching, and link-logging to del.icio.us
Ruby
9
star
15

benchmark_unit

Machine-independent benchmark assertions for your Ruby unit tests
Ruby
7
star
16

fftw3

Gem version of T. Horinouchi's ruby-fftw3.
C
7
star
17

rv

A little init.d system for running Camping apps
Ruby
6
star
18

twist

A Ruby script for logging your system events to Twitter
Ruby
6
star
19

mysqlconfs

MySQL configuration examples
5
star
20

charm_http

A parallel EC2 driver for running the hummingbird HTTP load testing tool against Heroku.
Ruby
4
star
21

shadow

A zero-configuration RESTful ActiveRecord server
Ruby
3
star
22

autobench-grapher

Ruby
2
star
23

wordpress_importer

Script that can import a homegrown blog into WXR format for WordPress.com.
Ruby
1
star
24

cloudbur.st

Cloudbur.st static assets
HTML
1
star
25

js-node

JavaScript
1
star
26

bax

A hacky blog engine that runs via recursive SSI includes
Ruby
1
star
27

scala-finagle

Scala
1
star
28

search_benchmark

Ruby
1
star
29

stub

A stub gem, including C extension.
Ruby
1
star