Five tools for profiling Rails apps

March 01 Bullet_white By Derek Bullet_white Comments Comments

Starting with Fiveruns TuneUp in 2008, a number of in-browser Rails profilers have come, gone, or continue to exist but in a zombie-like half-alive state. Finding profilers that reliably work in 2017 with little effort was a bigger challenge than I thought. Here's a 2017 summary of the Rails profiler ecosystem: what works, what doesn't, and each profiler's niche.

rack-mini-profiler

miniprofiler

While its name might include "mini", rack-mini-profiler is actually the feature-packed beast of Rails profiling options. rack-mini-profiler instruments database calls, profiles the callstack with flamegraphs, and provides a number of memory-related metrics.

rack-mini-profiler "just works" against the Rails 4 and Rails 5 apps I tested.

rack-mini-profiler pros

  • Just works
  • Provides solid traces w/breakdowns of partial rendering times database query times
  • Hooks into other tools like memory profiling and stackprof
  • Possible to run in production
  • No noticeable performance overhead for timing instrumentation

rack-mini-profiler cons

  • It's not possible to run multiple types of profilers (ex: timing, memory, stackprof) at once
  • Some profiling modes - like memory and stackprof - have to be explicitly run vs. only accessed if you see an anolomly
  • I've had odd issues where AJAX requests aren't captured that I've had trouble narrowing down

DevTrace

devtrace

DevTrace is Scout's free Rails profiler and is included with the scout_apm gem. DevTrace provides the same level of traces Scout provides for app monitoring - instrumenting view rendering, database calls, and memory allocations.

When run with ScoutProf, Scout's stack profiler, it also profiles your custom code.

DevTrace "just works" for Rails apps.

DevTrace pros

  • Just works
  • Traces are easily readable and are also consistent with those collected during monitoring
  • Profiles timing, memory, and the stack on every request
  • No noticeable performance overhead
  • Easy to share traces with your team

DevTrace cons

  • Only supports the development environment
  • Framework support is limited to Rails

Rails Panel

rails panel

One part Ruby gem and one part Chrome extension, Rails Panel exposes details on your app's requests in the Chrome Developer Panel. Rails Panel instruments ActiveRecord and rendering calls.

Rails Panel Pros

  • Unobtrusive - expose the developer panel to reveal details and hide it when it isn't needed.
  • Integrates with popular editors to provide direct links from backtraces
  • No configuration required outside of the gem and Chrome extension install

Rails Panel Cons

  • The Chrome Developer Panel must be open to capture request details - if it's hidden an issue occurs, the request isn't captured.
  • Framework support is limited to Rails
  • Tracing isn't as advanced as rack-mini-profiler or DevTrace
  • Tracing is limited to ActiveRecord and rendering calls

Profilers I struggled with

  • Rack::Insight - I didn't have much luck getting this going against a Rails 4 app. Only my initial request appeared in the trace panel, app response times were noticeably slower, and the metrics I did see where not at the level of detail of rack-mini-profiler or Scout DevTrace.
  • Peek - I was able to get this partially working against a Rails 4 app but several of the panels didn't work, including the performance bar (a key panel). The initial configuration is more involved than all of the other tools as well. Peek also didn't run, or caused "stack level too deep errors" when app monitoring services like New Relic or Scout ran alongside it. All of the other profilers got along find with APM services.

Which profiler should I use?

While rack-mini-profiler, DevTrace, and Rails Panel can run simultaneously without error, that's likely information overload. These are the sweet spots for each of the above profilers:

rack-mini-profiler

Not intimidated by lots of instrumentation data? rack-mini-profiler is a great fit for developers that enjoy detailed statistics on performance. This is a tool that's not afraid of dumping a significant amount of data into a developer's lap.

rack-mind-profiler is also the only option for two areas:

  1. Non-Rails apps (ex: Sinatra)
  2. Running in production

DevTrace

Do you value polish and filtering on performance metrics over a raw dump of data? DevTrace works to distill information: it provides timing, memory, and sampling data like rack-mini-profiler but in a more compressed presentation.

Rails Panel

Are you after a cleaner way to view your development log file and not deep transaction traces? Rails Panel fits the bill.

Also See

Subscribe for more

Want more Ruby insights like this delivered monthly to your inbox? Just put your email into the sidebar form.

Comments

comments powered by Disqus