Rails: webrick & lighttp/fcgi threading model


#1

I am using rails 1.0.0 on os x, and I can’t help but notice that
whenever I post a new request to my rails appsvr (webrick or
lighttpd/fcgi), it looks like my ~/.irbrc is reexecuted (I noticed that
bcoz I defined a constant in my .irbrc and the ‘constant xxx already
defined’ message keeps poping up in my rails log)

This got me thinking: I hope webrick (or lighttpd/fcgi) doesn’t start a
new ruby process whenever I ask for a new page ? (like some good old
cgi)

Maybe somebody can shed some light as to how requests are handled
there:

  • Is there a single ruby process which just spawn new threads whenever
    a new request comes in (probably using a thread pool) ?
  • If this is the case, any reason why my ~/.irbrc keeps being executed
    ?
  • if this is NOT the case, how is session data maintained between two
    page requests ?

thanks
-Didier


#2

Didier wrote:

This got me thinking: I hope webrick (or lighttpd/fcgi) doesn’t start a
new ruby process whenever I ask for a new page ? (like some good old
cgi)

Webrick is a development server, so it is starting a new ruby process
for every page.

You will get a better answer at the Rails Forum.

Christer


#3

On Jan 10, 2006, at 3:01 PM, Christer N. wrote:

Didier wrote:

This got me thinking: I hope webrick (or lighttpd/fcgi) doesn’t
start a
new ruby process whenever I ask for a new page ? (like some good old
cgi)

Webrick is a development server, so it is starting a new ruby process
for every page.

No, it does not start a new ruby process. WEBrick is a non-forking
pure ruby HTTP server.


Eric H. - removed_email_address@domain.invalid - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com


#4

Christer N. wrote:

Didier wrote:

This got me thinking: I hope webrick (or lighttpd/fcgi) doesn’t start a
new ruby process whenever I ask for a new page ? (like some good old
cgi)

Webrick is a development server, so it is starting a new ruby process
for every page.

How do you figure? I believe Webrick stays running and keeps application
code in memory. In development mode it will reload files, but that can
be configured.

You will get a better answer at the Rails Forum.

This is true, at least for the Rails-specific stuff, but I’d be
interested in any general observations on SCGI/fasctcgi Ruby stuff, as
other Web apps use these as well.

James

http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools


#5

Ok, so looking into the WEBrick code, it is indeed a non forking server
(meaning only one process is running). Now looking at the
webrick/httpserver.rb::run method it looks like it is also single
threaded. Fine.

As for the rails specific stuff, I tried to follow the rails code, but
I got lost into the action_controller module. The code starts to be a
little hard to follow, especially when you have tons of ‘send(method,
*arguments)’ all over :slight_smile:

Anyway, maybe somebody here knows: how come my .irbrc gets executed for
each new request ? (yeah, yeah, I am going to submit this question on
the rails forum…)

-Didier


#6

all right guys, after spending some more time staring at the code, I
found out why this is happening: active_support is going to start a
breakpoint server… which then starts an irb process… which then
reads and run my .irbrc…

thank you all for your help.

-Didier

ps: and btw, I made a mistake: WEBrick is not single threaded…


#7

On Tuesday 10 January 2006 4:01 pm, Christer N. wrote:

Webrick is a development server, so it is starting a new ruby process
for every page.

Webrick is much maligned because of the way that Rails operates with it,
but
the above is not true, in general.

Webrick is a pure ruby web server. It is used for development with
Rails
because it’s convenient to start, but very slow, with Rails, because
of the
way Rails uses it. That slowness is nothing inherent in Webrick itself.

Used without Rails, webrick is surprisingly fast, given that it is pure
Ruby,
and it is also quite stable and dependable. I use it for development
purposes quite often, and even on a fast connection, for light usage,
one
really can’t discern a different in speed between an app or dynamic site
running off of Webrick versus one running through Apache or lighttpd.
It is
a great tool.

Kirk H.


#8

On Jan 10, 2006, at 9:38 PM, removed_email_address@domain.invalid wrote:

all right guys, after spending some more time staring at the code, I
found out why this is happening: active_support is going to start a
breakpoint server… which then starts an irb process… which then
reads and run my .irbrc…

On top of this you’ll get a lot of code being re-loaded while in
development mode. You might want to run in production mode while
working out what is going on.

thank you all for your help.

-Didier

ps: and btw, I made a mistake: WEBrick is not single threaded…


Bob H. – blogs at <http://www.recursive.ca/
hutch/>
Recursive Design Inc. – http://www.recursive.ca/
Raconteur – http://www.raconteur.info/
xampl for Ruby – http://rubyforge.org/projects/xampl/