views:

63

answers:

1

Hi, I'd like to know why is there a need to restart the server (Mongrel/WEBrick) every time a model file is updated? I know it doesn't get loaded in if you don't do it - but is there any documentation out there that would explain why it does so?

Thanks!

+4  A: 

Development environments do not require you to restart the server if you change a model. They will reload the environment for each request if necessary.

Production environments are a different story. A Rails server (mongrel/passenger/webrick/etc) running in a production environment will only load your Rails environment once when the process is started. This takes a couple of seconds, as you might notice when starting the console which also loads your Rails environment. To avoid this overhead for each request the server will spawn a new thread from the loaded environment to handle each incoming request.

Because the server only responds to HTTP requests, and the usual signals. There's no good way to force an environment reload beyond always loading a fresh environment (like a development environment, or restarting the server.

EmFi
Thank you very much! This explains why its emphasized during all the tutorials.
RedNax
Correct me if I'm wrong but I don't believe the entire environment is reloaded per request. I'm under the impression that in the development environment that although classes are not cached (hence not needing to restart the server if you change a model or controller), ActionController doesn't cache any views, and routes are redrawn each request, I don't believe the whole environment is reloaded though as intializers are not reloaded per request.
Steve Graham
@Steve: You are indeed correct. plugins and initializers are loaded once when the server is started in development mode, but not with every request.
EmFi