I have labored under the (possibly naive) misconception that a Rails
app initialized and loaded on every request. Now I’ve found hints
that the core application loads and stays available for later
requests? How is this possible? I thought that the Ruby interpretter
loads everything into its own little happy process. Does Rails wait
around for requests on a port or something to keep it connected to the
webserver?
I’m working on understanding Rails Initialization and the full process
of the framework.
The Mongrel or WEBrick web servers do in fact stay running between
requests. In development model WEBrick will reload modified files. I
have yet to determine if it provides any ordering of those files or
just reloads the files on top of whatever was there. So far I have
not seen any indication that patches from one class are lost when
reloading another file so it is not simply just reloading files on top
of the current version.
A first request comes in. The rails app hasn’t been loaded yet.
The dispatcher sees that nothing is defined, so it loads
environment.rb
environment.rb loads boot.rb
boot.rb sees that the initializer is not present, so it loads
initialize.rb
The whole framework boots up to life.
Routing processes the request and a response is sent back to browser.
NOW…how is that Ruby environment persisted and able to handle the
next request sent to the web server? Assume Lighty. Lighty gets a
request and maybe passes it off to Mongrel. Mongrel is written in
Ruby and mongrels keep running. Is that why the next request given to
the mongrel loads the dispatcher, which sees RAILS_ROOT and skips
loading the environment, and processes the request?
If so, what does that mean if you are not using Mongrel? What if you
are simply using lighttpd? What keeps running the Rails-loaded Ruby
environment?
Lee Hericks
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.