-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a88ed6
commit 1b8c822
Showing
1 changed file
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,30 @@ | ||
# rack-profiler | ||
[![Build Status](https://travis-ci.org/iainbeeston/rack-profiler.svg)](https://travis-ci.org/iainbeeston/rack-profiler) | ||
|
||
This is my attempt to make a rack middleware that profiles memory usage in rails, with the aim of detecting memory leaks. | ||
This is my attempt to make a rack middleware that profiles memory usage in rails (or any rack-based app), with the aim of detecting memory leaks. After *every* request it takes a dump of the objectspace and saves it to a data store of your choice\*. | ||
|
||
This project was heavily inspired by blog posts by [@samsaffron](http://samsaffron.com/archive/2015/03/31/debugging-memory-leaks-in-ruby) and [@wagenet](http://blog.skylight.io/hunting-for-leaks-in-ruby/). | ||
|
||
\* Any object supporting the ~[]=~ method can be used as a data-store. I recommend [Moneta](http://github.com/minad/moneta), which has support for Redis and Amazon S3. | ||
|
||
## Getting Started | ||
|
||
After installing the gem, insert rack-profiler into your middleware stack: | ||
|
||
~~~ | ||
config.middleware.insert_after ActionDispatch::Static, Rack::Profiler, store: Moneta.new(:Redis) | ||
~~~ | ||
|
||
I'd recommend installing rack-profiler as low as you can in your stack. Preferably only requests that hit your own application code should be profiled. | ||
|
||
## Warnings | ||
|
||
*DO NOT USE THIS IN PRODUCTION* (it's *VERY* slow - I'd recommend running it on a close-copy of production instead) | ||
|
||
Every objectspace dump is unique to a particular ruby process. Make sure your server is only running a single worker when profiling. | ||
|
||
I've found that with unicorn, requests will usually time-out when using rack-profiler. Try increasing the ~timeout~ value in unicorn.rb. | ||
|
||
## How to find memory leaks | ||
|
||
Right now this bit is manual. rack-profiler will give you the objectspace for a running app. I'd recommend taking the objectspace dumps for several successive requests and looking for objects that aren't garbage collected, as @wagenet did in his [post on the Skylight blog](http://blog.skylight.io/hunting-for-leaks-in-ruby/). |