Keeping track of Rails Boot progress

by

Ruby on Rails can take a long time to boot so in some cases it can be useful to provide some kind of progress reporting (f.x. if you are considering using Rails in an embedded application).

RoR does not provide any direct means to monitoring the progress of the boot-process, so a little work is necessary. Changing the ruby source files involved in the boot process is not ideal from a maintenance standpoint and even if one does so, the progress report turns out to be very uneven. The best approach I could come up with was a Kernel hook which keeps track of when files are require‘d. Both easy to do and works surprisingly well for fine-tuned progress reporting.

# Hook into require so that we can track startup progress
module Kernel
 alias org_untracked_require_myAppName require
 def require(file, *extras)
 v=org_untracked_require_myAppName(file, *extras)
 $progress_coordinator.addWorkDelta(1,'Rails required '+file.to_s)
  unless progress_coordinator.nil? || file.nil? || !v
 v
 end
end
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.