[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

fastcgi and shared interpreters

james_b

12/8/2005 5:12:00 PM

I'm doing more work with fascgi and scgi, and I'm looking for some
clarification. Are there configurations for either of these where
multiple application processes are sharing the same Ruby interpreter?

If my own application code is not using threads, do I need to be
concerned with race conditions or data access conflicts?



Thanks,


James



--

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - Ruby Code & Style: Writers wanted
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools


8 Answers

Jeremy Kemper

12/8/2005 6:21:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Dec 8, 2005, at 9:12 AM, James Britt wrote:
> I'm doing more work with fascgi and scgi, and I'm looking for some
> clarification. Are there configurations for either of these where
> multiple application processes are sharing the same Ruby interpreter?

How you process requests in a FastCGI or SCGI handler is up to you.
The 'standard' way is to handle a single request at a time per-
process so you don't have to worry about threading issues. However,
you could just as well dispatch the request to threads or fork children.

Best,
jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDmHmaAQHALep9HFYRAhSoAKCF1n3VYnTXLWIU4A7hYLVaEnlR3gCdF3dp
Fri6gTJQWRPDW41EU0H5Y4c=
=Zyre
-----END PGP SIGNATURE-----


Ara.T.Howard

12/9/2005 3:41:00 AM

0

james_b

12/9/2005 7:47:00 AM

0

ara.t.howard@noaa.gov wrote:
> On Fri, 9 Dec 2005, James Britt wrote:
>
>> I'm doing more work with fascgi and scgi, and I'm looking for some
>> clarification. Are there configurations for either of these where
>> multiple
>> application processes are sharing the same Ruby interpreter?
>>
>> If my own application code is not using threads, do I need to be
>> concerned
>> with race conditions or data access conflicts?
>
>
> fastcgi is process based - you don't need to worry about any concurrent
> access
> __other__ than between any two processes. for instance, if your
> application
> did something like
>
> log = open "log", "w"
>
> log << 42
>
> then you could quite possibly have two processes writing to the log file
> since
> apache can, depending on configuration, spawn a few processes to handle
> requests. each request, however, defintely is running in one ruby
> interpreter.

Right. There's no telling what other app might be trying to access the
same external resource.

If I'm understanding this correctly, though, I need not be concerned
with contention issues any more than I would with a plain CGI app;
fastcgi and scgi are means of routing requests to persistent CGI
processes, but a given process will not be handling more than one
request at a time.

Thanks,



James


--

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - Ruby Code & Style: Writers wanted
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools


Jeremy Kemper

12/9/2005 8:10:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Dec 8, 2005, at 11:47 PM, James Britt wrote:
> If I'm understanding this correctly, though, I need not be
> concerned with contention issues any more than I would with a plain
> CGI app; fastcgi and scgi are means of routing requests to
> persistent CGI processes, but a given process will not be handling
> more than one request at a time.

Most FastCGI implementations work this way, but it is not a rule.

You are free to write a FastCGI server which handles concurrent
requests (with threads, async IO, forked children, etc.)

But most do not; programming in the CGI style is much simpler.
The choice is yours.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDmTvsAQHALep9HFYRAlEbAJ4iOsWTtEFblJq2HT2mHZeVKBPpSgCfXODP
EPmkmCVTbLyXo9RE/WaIpdw=
=BFqr
-----END PGP SIGNATURE-----


Jeremy Kemper

12/9/2005 8:16:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Dec 9, 2005, at 12:10 AM, Jeremy Kemper wrote:
> You are free to write a FastCGI server which handles concurrent
> requests (with threads, async IO, forked children, etc.)

In fact, FastCGI can handle concurrent requests on concurrent
connections on concurrent processes :) I've never done request
multiplexing; as far as I can tell, it's these complexities in its
protocol that led to SCGI.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDmT0bAQHALep9HFYRAt01AJ9+knr9SSFj/fbnDTGKSFPGTmeNjQCcDkb3
YMIAXrHpfFC0GNu0XRbxt44=
=tXcK
-----END PGP SIGNATURE-----


james_b

12/9/2005 8:29:00 AM

0

Jeremy Kemper wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Dec 8, 2005, at 11:47 PM, James Britt wrote:
>
>> If I'm understanding this correctly, though, I need not be concerned
>> with contention issues any more than I would with a plain CGI app;
>> fastcgi and scgi are means of routing requests to persistent CGI
>> processes, but a given process will not be handling more than one
>> request at a time.
>
>
> Most FastCGI implementations work this way, but it is not a rule.
>
> You are free to write a FastCGI server which handles concurrent
> requests (with threads, async IO, forked children, etc.)
>
> But most do not; programming in the CGI style is much simpler.
> The choice is yours.

I'm writing and deploying Rails and Nitro apps and using fastcgi/scgi at
different times, and have yet to see any discussion of threading in
relation to these. So my belief is that the fcgi and scgi code used in
such cases is not doing anything that puts conventional CGI-style code
at risk.

But I was curious if anyone knew of something to the contrary.


James
--

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - Ruby Code & Style: Writers wanted
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools


Jeremy Kemper

12/9/2005 8:56:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Dec 9, 2005, at 12:28 AM, James Britt wrote:
> I'm writing and deploying Rails and Nitro apps and using fastcgi/
> scgi at different times, and have yet to see any discussion of
> threading in relation to these.

Zed's SCGI Rails runner is threaded but serializes request processing
to emulate a single-threaded environment.


> So my belief is that the fcgi and scgi code used in such cases is
> not doing anything that puts conventional CGI-style code at risk.

Yes. It is safer to say that Rails and Nitro support CGI-style
programming.


> But I was curious if anyone knew of something to the contrary.

You could become contrary by rewriting dispatch.fcgi :)

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDmUaCAQHALep9HFYRAu2OAJ9ITo/NlynkzSH9gkUEJrt2wQBEPwCfWMHv
ZXfrMafBD6pylQejfDryFXk=
=zoA2
-----END PGP SIGNATURE-----


George Moschovitis

12/9/2005 9:19:00 AM

0

> Yes. It is safer to say that Rails and Nitro support CGI-style
> programming.


Nitro also supports multithreaded applications. Nitro and Og are (or
try to be) thread safe. The webrick and scgi adapters for Nitro do not
serialize the requests with a semaphore.

regards,
George.


--
http://www...
http://ww...
http://www.n...