[Ruby] Per user IO connections in Rails?

Scott Windsor swindsor at gmail.com
Fri May 23 08:56:22 PDT 2008


On Thu, May 22, 2008 at 12:19 PM, Atom Powers <atom.powers at gmail.com>
wrote:
>
> Maybe I am going about this all wrong.
> I've been assuming that once the server is started, all modules are loaded
> server-wide and variables are shared between sessions. But that may not be
> the case?
>

>
> So riddle me this:
> If I 'include Ldap' in application.rb are the instance variables in that
> module shared between all sessions, or are they unique for each session? or
> for each server/service?
> Could the answer depend on the service? script/server vs Apache fastcgi?
>

The way rails generally works is that each rails instance only ever serves
one web request at a time.  The fastcgi model (using apache or another
webserver), is that the webserver spins up new rails processes as needed.
These rails processes only ever serve one request at a time.  Class
variables are kept around between requests.  For the application controller,
it's constructed and destroyed for processing each request - that's how your
instance variables don't carry over from one request to another.  The only
caveat is running in development mode for rails (which is the default) -
since class caching is disabled, all clases are unloaded after rails has
served a request.

For mongrel, each mongrel server is multi-threaded and can listen to
multiple requests at the same time, but it always locks each time it
processes a rails request - the result ends up being very similar to
fastcgi, since you'll generally want to run multiple mongrels.

Session data always lives from request to request, and are generally better
to share information from one request to another. The reason for it is that
if you have multiple rails instances running, they can never share their
class variables or data, so the likelyhood of a user getting the same rails
instance can be fairly slim.


> I really appreciate the advice, this is my first Rails app. but Ruby is by
> far the most fun I've had programming in ... ever.
>

I'm glad you're enjoying :-)

- scott


>
> --
> --
> Perfection is just a word I use occasionally with mustard.
> --Atom Powers--
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
>


More information about the Ruby mailing list