MemoryTracker

MemoryTracker finds where the memory bloat comes from in a Rails application.

Features

Dashboard

Screenshot

The dashboard is at /memtracker in the host application (but you need to mount the engine in the app first, see below).

That's where the collected statistics are displayed.

What to look for?

Enabling MemoryTracker

Add it to your Gemfile:

gem 'memory_tracker'

To get access to the MemoryTracker UI and see the stats, the engine must be mounted at config/routes.rb

mount MemoryTracker::Engine => "/memtracker"

How does it work?

MemoryTracker uses system memory data and Ruby garbage collector statistics to find the memory currently used by The Rails processes, how many objects were allocated in Ruby heaps, how many heaps were created and how many times the garbage collector ran. The MemoryTracker middleware captures the data before and after each HTTP request and saves the deltas per controller/action in one or more stores.

MemoryTracker is implemented as a Rails engine and reports its statistics in a web page served by the application where it's embedded. The report currently includes data from the InMemoryStore.

Stores

MemoryTracker currently comes with 3 stores.

Config file

memory_tracker.yml

The config file is optional. If you choose to write one, place it in “#{Rails.root}/config”. In the absence of a custom config file, memory_tracker will fallback to the file linked above in the gem.

By creating you own config file, you can choose which stores are enabled and tune them. By default all stores are enabled. Here is a sample config file that enables only the InMemoryStore with a 4 hour long data window:

defaults:   &defaults
  stores:
    - name: memory
      window_length: 14400


production:
  <<: *defaults

development:
  <<: *defaults

test:
  <<: *defaults

Requirements

The gem has been tested and is compatible with: * Ruby 2.0 * Ruby 1.9 but 1.9 GC.stat does not include the total_allocated_object number so its value remains at 0 in MemoryTracker. * Rails 3.2, Rails 4.0

Tips

Coming soon

Contributing to memory_tracker

References

Copyright

See LICENSE.txt.