Page 1 of 1

FastCGI multiplexing

Posted: Mon Nov 14, 2016 7:19 pm
by greyhoundcode
Right now PB's FastCGI implementation supports threading, which is great. I'm wondering though - if this is viable - if support for handling multiple requests 'concurrently' without creating a new thread per request could be added?

Semi pseudo-code:

Code: Select all

Procedure AddToResponseQueue(fastCgiHandle.l)
    ; Stores handle in a global map
EndProcedure

Procedure ProcessWaitingQueue()
    ; Pull next waiting request out of the queue
    handle.l = GetWaitingRequestHandle()

    ; Perform any db queries / other time intensive work etc
    ; Respond!
    WriteCGIString(handle.l, "Response")    
    FinishFastCGIRequest()
EndProcedure

CreateThread(@ProcessWaitingQueue(), 0)

While WaitFastCGIRequest()
    handle.l = ReadCGI()
    AddToResponseQueue( handle )
Wend
So yes, I'm using threading, but I may essentially have a single thread putting together the responses (and still want to accept new incoming requests). I basically want to multiplex between them, and have request handles to facilitate that.

Re: FastCGI multiplexing

Posted: Wed Nov 21, 2018 11:55 pm
by Poshu
*bump*

Same here : request handle would allow me to speed up my server considerably.