rails: webrick & lighttp/fcgi threading model

D

didier.prophete

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
 
C

Christer Nilsson

Didier said:
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
 
E

Eric Hodel

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.
 
J

James Britt

Christer said:
Didier wrote:




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
 
K

Kirk Haines

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 Haines
 
D

didier.prophete

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 :)

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
 
D

didier.prophete

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...
 
B

Bob Hutchison

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 Hutchison -- 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/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top