# Rails: webrick & lighttp/fcgi threading model

**URL:** <https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106>\
**Category:** Ruby\
**Created:** [January 10, 2006, 11:50pm UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106 "2006-01-10T23:50:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 10, 2006, 11:50pm UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/1 "2006-01-10T23:50:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 12:00am UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/2 "2006-01-11T00:00:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 1:17am UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/3 "2006-01-11T01:17:45Z")

</div>

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](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 1:26am UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/4 "2006-01-11T01:26:48Z")

</div>

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](http://www.ruby-doc.org) - Ruby Help & Documentation  
[Ruby Code & Style](http://www.artima.com/rubycs/) - The Journal By & For Rubyists  
[http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys  
[http://www.30secondrule.com](http://www.30secondrule.com) - Building Better Tools

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 2:24am UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/5 "2006-01-11T02:24:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 3:39am UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/6 "2006-01-11T03:39:24Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 1:35am UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/7 "2006-01-11T01:35:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 2:27pm UTC](https://www.ruby-forum.com/t/rails-webrick-lighttp-fcgi-threading-model/52106/8 "2006-01-11T14:27:58Z")

</div>

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/](http://www.recursive.ca/)  
hutch/\>  
Recursive Design Inc. – [http://www.recursive.ca/](http://www.recursive.ca/)  
Raconteur – [http://www.raconteur.info/](http://www.raconteur.info/)  
xampl for Ruby – [http://rubyforge.org/projects/xampl/](http://rubyforge.org/projects/xampl/)
