FastCGI multiplexing
Posted: Mon Nov 14, 2016 7:19 pm
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:
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.
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