Skip to content

Performance Monitoring

Mac Peters edited this page Dec 22, 2020 · 9 revisions

Performance Optimization

Most Effective Optimizations

  • Active Record Queries: Don't need the whole object? Just select the part you want. Need several relational objects? Select them all at once, instead of doing separate queries.
  • never use exceptions as flow control. They are up to 32x slower.

Tools

Mini-Rack-Profiler

This gem should be included in all our apps, and enabled in production - partially because our dev environments are different from production, and also because it is designed for production use. It can be restricted by user role, and it can be set to hidden unless someone explicitly wants to see it.

# use option/p to toggle
Rack::MiniProfiler.config.start_hidden = true

This gem will show a speed badge in the top left corner. Clicking that gives you access to information about sql queries, server response times, broken down by partial.

?pp=help at the end of a query on any page will show you a complete list of features and how to trigger them.

Flamegraph

This is an optional add to the mini-rack-profiler gem. ?pp=flamegraph will show you a flamegraph of where time was spent in the app, with the x axis being time, and the y axis being how deep in the stack it happened.

Memory_Profiler

Another optional add to mini-rack-profiler. ?pp=profile-memory tells us where in code different memory is being allocated

More Gems/Tools

  • Bullet: Checks for query optimizations 
  • lol_dba: rake tasks that scan your application models and displays a list of columns that probably should be indexed
  • Metric Fu: A fist full of code metrics
  • Ruby Prof: Code profiler - faster, more options than standard ruby profiler
  • Skylight: Smart profiler that follows through an action to find the pain points.
  • Stack Prof:  A sampling call-stack profiler for Rub