Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I profile booting of a Rails application?

Simple problem, I have a legacy Rails 2.3 application and it takes quite long to do anything. rake takes over 25 seconds, but it doesn't look like anything is really happening.

Is there any simple way I can just get some kind of profiler dump from the time when the app is loading, to see which methods take the longest time?

A solution for both Rails 2.3 and 3.1 would be even more helpful.

like image 643
Jakub Arnold Avatar asked Dec 23 '11 09:12

Jakub Arnold


People also ask

How does a Rails application start?

A Rails application is usually started by running bin/rails console or bin/rails server .

How do Initializers work in Rails?

An initializer is any file of ruby code stored under /config/initializers in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded.

What command will start a Rails server?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .

Why my Rails server is not working?

The problem could be that webpacker isn't stalled or your system can not locate it. So installing webpacker can be your next step. Try running this command in your terminal. After running the command navigate to your rails application and run the rails server command.


2 Answers

Profile a rake task that requires the rails environment, something like this:

 desc "Load it"
 task :loadit => :environment do

 end

then profile with ruby-prof

ruby -Ilib -S ruby-prof -p graph_html `which rake` loadit > profile.html

It ought to work with rails 2.3 have only tested it on 3.x but I see no reason why it should not work.

like image 60
sunkencity Avatar answered Oct 11 '22 12:10

sunkencity


You could start your application with a profiler hooked in, e.g. ruby-prof or perftools.rb. While it's still starting up, launch a HTTP query against it, which would try go GET a /kill_me route as soon as the application starts. /kill_me could cause your application to gracefully die by calling exit. As a result you've got a profile of your startup.

like image 34
Jan Avatar answered Oct 11 '22 14:10

Jan