Profiling Rails Apps with Rack-Mini-Profiler

This tutorial will discuss profiling Ruby on Rails Applications using rack-mini-profiler gem. rack-mini-profiler gem helps finding performance bottlenecks by showing speed badge on every page which can be configured to be displayed in particular environments. E.g. development/staging/production environment.

How to Install

You can install Rack-Mini-Profiler gem by command -

$ gem install rack-mini-profiler

This command will help you install latest stable version of this gem.

rack-mini-profiler

Integration with Rails Application

1. Add to Gemfile

You need to add this to Gemfile in the environment that you desire, we recommend you to add this gem in your development environment to measure the performance of your pages.

group :development, :test do
  gem 'rack-mini-profiler'
end

This will add gem in development and test environments only.

2. Bundle

After adding this gem to your desired environment you need to bundle install so that Rails application gets configured with the gems listed in the Gemfile. This can be done by following command,

$ bundle install

After this, you need to test by starting the server.

3. Start the Server

Then you can test how your profiling is done using this gem by starting the server and opening any page of your Rails application. Rails server can be started by following command:

$ rails server

Nest step is testing your Rails App.

4. Sample output with Interpretations

rack-min-profiler-demo

This is small snippet how the profiling result is shown by rack- mini-profiler. This shows time required to render the action. This also gives expanded view where it shows the queries executed and the amount of time taken by each query and so on.

Try exploring this gem, you will get more performance monitoring features as you start using this gem.

Conclusion

rack-mini-profiler helps in identifying performance bottlenecks and eliminating them. After checking out facts shown speed badge of rack-mini-profiler you can easily optimise queries and code as needed.

Related Post

To measure performance of Rails Applications, you might want to check out Rails Meta_Request article

-->