Ruby on Rails Monday, December 27, 2010

On Sun, Dec 26, 2010 at 11:44 PM, Fearless Fool <lists@ruby-forum.com> wrote:

> What happens in a Rails app between http requests?  Is it torn down
> entirely and re-started at the next request?  I know that's a rather
> open-ended question, but the answer has implications for code such as:
> =====
> class User < ActiveRecord::Base
>  SOME_CONSTANT = difficult_to_compute_initialization_value()
>  ...
> end

By default, in development mode the User class will get redefined in
each request (specifically, in every request that uses it). So the
costly init will be run per request, the benefit is live updates of
new code without server restarts, which is handy for development.

In production mode by default you get the class defined once per
process, so that costly initialization will occur once per process. A
process will typically serve lots of requests, and the process pool is
managed by the software that runs your application, eg Phusion
Passenger.

The flag that controls this behaviour is cache_classes, you'll see it
in config/environments/*.rb.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment