joeloui
joeloui

Reputation: 202

Count the amount of queries in Rails

I'm trying to optimize my site, in order to do that I want to know which action is making more queries than others. Is there anyway to know the amount of DB hits made by one action?

Upvotes: 12

Views: 10298

Answers (3)

Juan Alonso
Juan Alonso

Reputation: 2350

This gem will do exactly what you need: show the number of db queries issued per action:

https://github.com/makandra/query_diet

Upvotes: 4

Naveed
Naveed

Reputation: 11167

i found these gem very helpful for inspecting issues and optimizing queries

Upvotes: 11

Aj Gu
Aj Gu

Reputation: 1439

You could look at the rails log to see what & how many queries are being fired for each request. But its usually pain go though the log each time to see which request are taking time.

Usually I use newrelic gem in development to see which actions are taking more time and will try to optimize the queries. Refer to http://newrelic.com/docs/ruby/developer-mode for more info on newrelic in development model.

Also based on the database and rails version there are other gems ( https://github.com/flyerhzm/bullet ) which tells you how queries are performed in a particular request.

Upvotes: 0

Related Questions