Better performance insights with gem `rails_performance`

Posted . Visible to the public.

Even if you don't make any beginner mistakes like N+1 queries or missing DB indices, some requests can have bad performance. Without good performance metrics, you probably won't notice this until it's too late.

We investigated multiple gems and found that rails_performance ( https://github.com/igorkasyanchuk/rails_performance Show archive.org snapshot ) provides a lot of valuable information with very little setup cost. It only needs Redis which we use in the majority of our applications anyway.

Features

  • A nice "Dashboard"
  • The "Request Analysis" screen
    • Aggregated requests by route
    • Separately lists view rendering and DB query durations
    • Good for spotting problematic endpoints
  • The "Recent requests" screen (1 hour history)
    • Shows individual requests
    • Provides the full list of DB queries per request, color coded so you immediately spot slow queries
    • Good for local debugging, as your latest request will always appear at the top
  • The "System" screen
    • Optional, if you install additional dependencies
    • Gives you rudimentary insights into your system load
  • The "Slow requests" screen (4 hour history)
    • Only problematic requests (> 500 ms)
    • Longer history than "Recent requests"
  • The "500 Errors" screen
    • self-explanatory and hopefully always empty
  • The "Custom Events" screen
    • Let's you easily add custom monitoring around certain code paths

Immediately effective

We deployed this to production and immediately spotted a slow and frequently used endpoint in "Request Analysis". The DB request list on the "Recent requests" screen gave away the culprit pretty clearly:

Image

The fix was 2 lines of code that dropped the query duration by more than 300ms on average.

Klaus Weidinger
Last edit
Klaus Weidinger
License
Source code in this card is licensed under the MIT License.
Posted by Klaus Weidinger to makandra dev (2025-05-30 09:47)