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
If String Is Empty Then Return Some Default Value
Find or Create Record Through Factory_Girl Association
Copying Gems from Previous Version of Ruby in Rbenv
How to Convert a JSON Formatted Key Value Pair to Ruby Hash with Symbol as Key
Ruby - Can't Modify Frozen String (Typeerror)
Can't Install Ffi -V '1.9.18' on MACos Catalina
Rspec: How to Test File Operations and File Content
How Much Performance Do You Get Out a Heroku Dynos/Workers
Ruby's <=> Operator and Sort Method
Error Installing Gem Capybara-Webkit
Setting Up the Logger in Rails 3
Restoring Rails 3's Bundle Install Path... It's Now Install in My Root
How to Find the Source File for a Rake Task
File.Open, Open and Io.Foreach in Ruby, What Is the Difference