Skip to content

Provides the ability to visualise and query the references between objects in Ruby's heap by exporting the heap into a Neo4j graph database

Notifications You must be signed in to change notification settings

joshuafleck/ruby_heap_graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby Heap Graph

Provides the ability to visualise and query the references between objects in Ruby's heap by exporting the heap into a graph database (Neo4j).

Useful for investigating memory leaks, it allows one to:

  • Search by class and analyze the references held in memory by that class
  • Search for objects that may be leaking memory by aggregating their references

Usage

  1. Add the Gem to your Gemfile

    gem 'ruby_heap_graph', git: '[email protected]:joshuafleck/ruby_heap_graph.git'
  2. Trigger the graph to be built in your application. You will be presented with a prompt you must accept before the export will proceed. Note: The initial installation of Neo4j may fail the first time with a Directory not empty error - re-run the build to get around this.

    RubyHeapGraph.build
  3. Open Neo4j in your browser: http://localhost:7474. Use Cypher (Neo4j's query language) to query the graph.

Graph

How it works

It uses the Ruby ObjectSpace library to find all reachable objects in memory for each object in the Ruby process. It dumps the object ids, class names, and object references for each object to temporary file, then it runs the Neo4j import tool to load this information into a graph database. It also performs the following:

  1. Installs Neo4j
  2. Stops Neo4j during the import
  3. Removes any existing Neo4j database
  4. Restarts Neo4j once the import is complete

Querying the graph

Finding objects of a particular class (ActionController::Railtie):

MATCH (n:`ActionController::Railtie`) RETURN n LIMIT 25

Finding the objects with the most references:

MATCH ()-[r:REACHABLE_FROM]->(parent)
RETURN parent, COUNT(r)
ORDER BY COUNT(r) DESC
LIMIT 10

About

Provides the ability to visualise and query the references between objects in Ruby's heap by exporting the heap into a Neo4j graph database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages