loading localhost:3000/projectszzzzz takes forever to load > 2min

4 views
Skip to first unread message

tom

unread,
May 23, 2019, 3:03:08 PM5/23/19
to Ruby on Rails: Talk
i have roughly 30 resources in routes, 10 scopes, a few nested resources.  how can i find out what the problem is?

Walter Lee Davis

unread,
May 23, 2019, 3:52:16 PM5/23/19
to rubyonra...@googlegroups.com
Turn your logging level up to debug, and watch the queries that are being generated by ActiveRecord in order to load this route. Are you seeing multiple requests to the database, or one big honking joined query? Sometimes using joins is slower than eager loading (which generally loads in two or more queries). But for slow, nothing beats an N+1 query, where you load a bunch of objects, then make a separate query or more per object to gather associated records from other related models.

Without any more details about your setup (running on a Raspberry Pi? or bouncing your database connection off the moon?) it's impossible to say. But start there.

Walter

> On May 23, 2019, at 3:02 PM, tom <toma...@gmail.com> wrote:
>
> i have roughly 30 resources in routes, 10 scopes, a few nested resources. how can i find out what the problem is?
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMcMrB1ZLtn_v76RbW33vV1N-M%2B5Xypt3u1H-FBA342jDg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Ariel Juodziukynas

unread,
May 23, 2019, 3:56:37 PM5/23/19
to rubyonra...@googlegroups.com
Check the log, it tells you the time spent on each query to the database:

User Load (1.0ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 201356 LIMIT 1

Note that "1.0ms"

It also tells you how log it took to render the each view and the totals:

  Rendered shared/_menu.html.slim (74.7ms)
  Rendered shared/_footer.html.slim (251.1ms)
  Rendered shared/_flash_modal.html.slim (2.7ms)
Completed 200 OK in 48109ms (Views: 45777.0ms | ActiveRecord: 1670.4ms)


You can also use gems like miniprofiler or bullet (for N+1 Queries) that shows you some of that information in a friendlier way



El jue., 23 may. 2019 a las 16:03, tom (<toma...@gmail.com>) escribió:
i have roughly 30 resources in routes, 10 scopes, a few nested resources.  how can i find out what the problem is?

--

Ariel Juodziukynas

unread,
May 23, 2019, 3:57:23 PM5/23/19
to rubyonra...@googlegroups.com
*It also tells you how long it took to render each view and the totals:
Reply all
Reply to author
Forward
0 new messages