[fpc-pascal] How to use FCGI in threaded mode?

Michael Van Canneyt michael at freepascal.org
Mon Feb 16 11:23:25 CET 2015



On Sun, 15 Feb 2015, silvioprog wrote:

> On Sun, Feb 15, 2015 at 7:11 AM, Michael Van Canneyt <michael at freepascal.org> wrote:
> [...]
>       Very nice.
>
>       Some remarks:
>
>       - KeepConnection logic already existed. It is part of the fastcgi protocol.
>
>         Normally, the apache server must send a keepconnection option as part of the request.
>         See the 'FKeepConnectionAfterRequest' variable in TFCGIrequest, it is processed when
>         the FCGI_BEGIN_REQUEST block comes in and is checked after each request.
>
>         The fact that you apparently needed to introduce special processing means the proxy
>         module does not correctly set this option. To test, you can check the value of the flag
>         in the request handler.
>
>         I also suggest you look at the existing implementation of KeepConnection and see
>         where that needs to be changed, instead of introducing new KeepConnection handling.
> 
> 
> I saw, and it works fine in nginx, but ...
>
>       - if you really need to introduce  an additional flag, please put an extra flag in
>         ProtocolOptions. Something like 'poDefaultKeepConnection'.
>         Do not introduce new booleans 'options' when an option set exists...
> 
> 
> ... in Apache, using proxy mode, keepconn always returns true. =/ So we need to add a 'poProxyKeepConnection' flag.

Wait, I do not understand. 
If keepconn always returns true, then all should work as-is ? Why do you need the flag ?

What happens if you set enablereuse=off in the apache config ?

>  
>       - Don't change the constructor signature, that is bad practice.
>
>         A TComponent constructor must be Create(AOwner : TComponent);
>
>         if you really want to change it, just create another one:
>         Constructur CreateCustom(AOwner : TComponent; KeepConnection : Boolean);
>
>         For components, properties must always be settable after create,
>         otherwise streaming does not work correctly.
> 
> 
> Done. Please see the code in attached (some changes in mycustfcgi too).

Thank you.

> 
> After your tips, now I'm able to implement the changes in original custfcgi and send a patch. One more question before continuing: after implementing the pool, we will still need RequestsArray?

Normally yes, even more so than in the current implementation. 
IMHO you will maybe need 2 arrays: Incoming (request), outgoing(response).

- New Request comes in. 
- No thread to handle request is available in pool.
- Request is accepted and put in incoming requestsarray.
- Check outgoing response array, send back any responses.
- When Thread finishes a request, puts it in outgoing responses array.

Details will depend heavily on the way the pool is handled.

Michael.


More information about the fpc-pascal mailing list