Last couple of days I needed to analyse some performance issues on a Rails application that I was working on.

So I started my research for new tools for my “engineering belt” and I have found some helpful tools.

I am quite newbie on ruby&rails world, since I only started working with rails, more deeply (not as playground :D ), in the last year. As already happen to me in the past, when I “switch” from one ecosystem to another, I always try to take a look for similar tools and good stuff that I am used to use on other ecosystems. It happen when I returned to .net after working with java for a couple of years, that by the way opened my eyes for a lot of stuff.

So when I am working on .NET ecosystem I always use Glimpse or MiniProfiler, both are amazing tools and a requirement for .net development. When i started looking for profiling tools for ruby, I had found that Sam Saffron started a ruby port for MiniProfiler and I give it a try. The port is awesome as I suspected. It details all database requests and times and also some extra client side profiling.

Another useful tool is peek that provide multiple peek views that show performance measures and counters, such as number and execution time of queries made to pg, memcache, mongo, redis and other kind of views.

It shows you bar like the one bellow.

The peek bar is really nice to have quick snapshot of the request, the MiniProfiler is awesome to discover what is wrong.

We can even use MiniProfiler with Rails API, we can execute an API request and get the response header “X-MiniProfiler-Ids” and use it on the share handler, that retrieve a full page with all the information.

/mini-profiler-resources/results?id=header-id

Using the previous approach would be fairly easy to read the headers from server logs and collect data, that could be used for statistics. I will probably try to do it with StatsD. Any tip for something like this? Give me some feedback.

Now, just go there and give it a try!

I think both tools are quite easy to configure and that’s why I will not put any information about it here.

Just a side note, you will see a huge number of queries that retrieve table schemas and others, don’t freak out. It’s the way ActiveRecord check a lot of stuff. In production mode it is cached and in development on the second hit the queries, aren’t executed.

Other useful links:

https://github.com/MiniProfiler/rack-mini-profiler

https://github.com/peek/peek

http://samsaffron.com/archive/2012/07/12/miniprofiler-ruby-edition

http://railscasts.com/episodes/368-miniprofiler