what happens between http requests?

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:

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

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.

- ff

Best,

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.

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.