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 ====Is there a writeup (and guiding principles) for the lifecycle of a Rails app? Or should I just not worry about this sort of thing until I actually deploy my app? TIA. - ff -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fearless Fool wrote in post #970802:> What happens in a Rails app between http requests?Generally nothing.> Is it torn down > entirely and re-started at the next request?No, at least not in production mode.> 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 > ====> Is there a writeup (and guiding principles) for the lifecycle of a Rails > app?You''re Or should I just not worry about this sort of thing until I> actually deploy my app? > > TIA. > > - ff-- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fearless Fool wrote in post #970802:> What happens in a Rails app between http requests?Generally nothing.> Is it torn down > entirely and re-started at the next request?No, at least not in production mode.> 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 > ====> Is there a writeup (and guiding principles) for the lifecycle of a Rails > app?You''re overthinking again. It''s just There.> Or should I just not worry about this sort of thing until I > actually deploy my app?Good idea. Of course, you should be deploying all the time, even if only to a staging box.> > TIA. > > - ffBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Sun, Dec 26, 2010 at 11:44 PM, Fearless Fool <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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() > ... > endBy 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Mon, Dec 27, 2010 at 11:10 AM, Xavier Noria <fxn-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> 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.Ah, depending on the preloading strategy of the production server this could be even once per application instance. But unless you use something weird like CGI, by default the class-level code will not run in each request in production mode. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.