How to Debug a Slow Rails App Boot Time

How can I find out why my app is slow?

If it is just slow on the first time you load it is probably because of passenger killing the process due to inactivity. I don't remember all the details but I do recall reading people who used cron jobs to keep at least one process alive to avoid this lag that can occur with passenger needed to reload the environment.

Edit: more details here

Specifically - pool idle time defaults to 2 minutes which means after two minutes of idling passenger would have to reload the environment to serve the next request.

Rails startup performance: how to trace and debug

You can get a pretty good walkthrough by adding pry and pry-nav to your Gemfile

# Gemfile
gem 'pry'
gem 'pry-nav'

Once this is in place, you can simply add binding.pry to the top of one of the files loaded early on, such as environment.rb or boot.rb. (This assumes that you're running on localhost:3000, otherwise things get more complicated.) Restart your app and you should be placed into a pry session. Us next to step through each line of code your app hits on startup! You can add multiple binding.pry lines throughout your code if you want to jump from one to the other, just type exit to move to the next one.

This will not benchmark your app, but it will allow you to step through what your app is doing, which might in itself allow you to actually experience what is taking so long.

How to diagnose slow rails / rake / rspec tasks

Thanks to @MaxWilliams for the link to this post How do I debug a slow rails app boot time?

I started using Mark Ellul's Bumbler - http://github.com/mark-ellul/Bumbler

It gave me exactly what I wanted - an insight into what's going in the background and which gems are taking the time. Of course I still need to speed up the slow ones (fog and authlogic seem to be two of the main culprits). But that's at different question.



Related Topics



Leave a reply



Submit