[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rails: webrick & lighttp/fcgi threading model

didier.prophete

1/10/2006 10:44:00 PM

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

7 Answers

Christer Nilsson

1/10/2006 11:01:00 PM

0

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

--
Posted via http://www.ruby-....


Eric Hodel

1/11/2006 12:16:00 AM

0

On Jan 10, 2006, at 3:01 PM, Christer Nilsson 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 Hodel - drbrain@segment7.net - http://se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...




james_b

1/11/2006 12:24:00 AM

0

Christer Nilsson 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.ru... - Ruby Help & Documentation
http://www.artima.c... - The Journal By & For Rubyists
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools


khaines

1/11/2006 12:35:00 AM

0

On Tuesday 10 January 2006 4:01 pm, Christer Nilsson 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 Haines


didier.prophete

1/11/2006 1:19:00 AM

0

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

didier.prophete

1/11/2006 2:34:00 AM

0

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

Bob Hutchison

1/11/2006 1:27:00 PM

0


On Jan 10, 2006, at 9:38 PM, didier.prophete@gmail.com 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 Hutchison -- blogs at <http://www.rec...
hutch/>
Recursive Design Inc. -- <http://www.rec...>
Raconteur -- <http://www.raconteur...
xampl for Ruby -- <http://rubyforge.org/projects/...