Fastcgi and shared interpreters

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.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
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

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

···

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?

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.

regards.

-a

···

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?

--

ara [dot] t [dot] howard [at] noaa [dot] gov
all happiness comes from the desire for others to be happy. all misery
comes from the desire for oneself to be happy.
-- bodhicaryavatara

===============================================================================

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

···

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.

--

http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
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

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

···

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.

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

jeremy

···

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

Jeremy Kemper wrote:

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

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

···

On Dec 8, 2005, at 11:47 PM, James Britt wrote:

--

http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
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

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

jeremy

···

On Dec 9, 2005, at 12:28 AM, James Britt wrote:

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.gmosx.com
http://www.navel.gr
http://www.nitrohq.com