Multi-threaded FastCGI servers

Peter Colson <pcolson-eepq2T/[email protected]>
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
Hello,

I'm in the process of modifying a single-threaded FastCGI server. I'm 
trying to make the server multi-threaded by using Posix threads and the 
FastCGI API's in one of the two ways, as follows:

pcreate_thread(&AcceptThread, 0, (void*)&AcceptThreadFunc, 0);
...
AcceptThreadFunc(...)
{
     FCGX_Request FcgiReq;
     FCGX_InitRequest(&FcgiReq, 0, 0);
     while (FCGX_Accept_r(&FcgiReq) >= 0)
     {
         // Do the work.
     }
}

Or:

FCGX_Request FcgiReq;
FCGX_InitRequest(&FcgiReq, 0, 0);
while (FCGX_Accept_r(&FcgiReq) >= 0)
{
     pcreate_thread(&WorkerThread, 0, (void*)&WorkerThreadFunc, 0);
}
...
WorkerThreadFunc(...)
{
     // Do the work.
}

I have read that it is possible when using multi-threading in FastCGI 
to:

a). Put the entire accept loop into the worker thread, as in the first 
code segment (or the threaded.c example), or
b). Have just a single accept loop and put just the code within the 
accept loop into a worker thread.

Is this correct? If it is, option b) would imply just a single instance 
of an FCGX_Request variable meaning, in turn, that only one FcgiReq.out 
would ever be used/accessed by, say, FCGX_FPrintF/PutS. How is this 
different from just using FCGI_stdout in a single-threaded FCGI_Accept 
loop?

I understand that FCGI_Accept is not thread-safe, whereas FCGI_Accept_r 
is, but in option b) the accept loop is outside of the worker thread, 
so does it matter which accept API is used? I guess, it might if 
FCGI_fwrite, say, is not thread-safe, since that would be used in an 
FCGI_Accept loop, but not in a FCGX_Accept_r accept loop...

Basically, is either a) or b) a preferable solution? Is one better in 
some circumstances, but not others?


Regards,
Peter Colson.

___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.