Forum: Ruby rails: webrick & lighttp/fcgi threading model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B389820ea2e2ee4f166930dea947a303?d=identicon&s=25 unknown (Guest)
on 2006-01-10 23:50
(Received via mailing list)
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
Af95bdaf87958c40150b813e94381bfd?d=identicon&s=25 Christer Nilsson (christer)
on 2006-01-11 00:00
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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-01-11 01:17
(Received via mailing list)
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://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
Bc6d88907ce09158581fbb9b469a35a3?d=identicon&s=25 James Britt (Guest)
on 2006-01-11 01:26
(Received via mailing list)
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.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
1b5341b64f7ce0244366eae17f06c801?d=identicon&s=25 Kirk Haines (Guest)
on 2006-01-11 01:35
(Received via mailing list)
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
B389820ea2e2ee4f166930dea947a303?d=identicon&s=25 unknown (Guest)
on 2006-01-11 02:24
(Received via mailing list)
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
B389820ea2e2ee4f166930dea947a303?d=identicon&s=25 unknown (Guest)
on 2006-01-11 03:39
(Received via mailing list)
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...
E3c79c779c0b390049289cdfe7cb9705?d=identicon&s=25 Bob Hutchison (Guest)
on 2006-01-11 14:27
(Received via mailing list)
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.recursive.ca/
hutch/>
Recursive Design Inc.          -- <http://www.recursive.ca/>
Raconteur                      -- <http://www.raconteur.info/>
xampl for Ruby                 -- <http://rubyforge.org/projects/xampl/>
This topic is locked and can not be replied to.