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

silvioprog silvioprog at gmail.com
Sun Feb 15 03:51:33 CET 2015

On Sat, Feb 14, 2015 at 2:12 PM, silvioprog <silvioprog at gmail.com> wrote:

> On Sat, Feb 14, 2015 at 3:18 AM, silvioprog <silvioprog at gmail.com> wrote:
> [...]
>> I came up with a question: how can I configure the FastCGI to accept more
>> than one request per connection? Is it possible in proxy mode?! ...
> I'm using Apache24 to debug the draft app, and today I've seen the
> following information on Apache documentation:
> ===
> mod_proxy_fcgi
> <http://httpd.apache.org/docs/trunk/mod/mod_proxy_fcgi.html> disables
> connection reuse by default, so after a request has been completed the
> connection will NOT be held open by that httpd child process and won't be
> reused. If the FastCGI application is able to handle concurrent connections
> from httpd, you can opt-in to connection reuse as shown in the following
> example:
> Single application instance, connection reuse
> ProxyPass /myapp/ fcgi://localhost:4000/ enablereuse=on
> Source: http://httpd.apache.org/docs/trunk/mod/mod_proxy_fcgi.html.
> ===
> I downloaded the httpd-2.4.12-win64-VC11.zip package, now I'm going to
> debug my app using this option ...

I was able to make the example works in "enablereuse=on" mode! =)

It was not necessary to change the mycustfcgi.pas, it is the same as the
previous example.

This made the application more responsive, now I hold the F5 key on the
browser and I can see the millisecond changing on the screen, even with
another tab "locked" in a 10-second loop. In the first example it was not

In that second example was added the "KeepConnection" property. If it is
False, the application will work as the first example that I sent: each
connection is closed in the end of request. If it is True, it will only
open a new thread if the first thread was still occupied in any processing,
otherwise the AcceptConnection of the application will be used.

I'm really impressed with the great performance achieved, please check this
log below (Chrome debug the result):

KeepConnection = False

*Status 200 OK - Loading time: 1022 ms*

KeepConnection = True

*Status 200 OK - Loading time: 8 ms*

To test it, download the attached example, unzip and run it. Using Apache
2.4.12+, make the following change in your httpd.conf:

LoadModule proxy_module modules/mod_proxy.so
ProxyPass /test fcgi://localhost:8080/ enablereuse=on
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

PS: in the code there is the comment "we will in Place the thread pool here
...", showing that at that point we will implement the thread pool, with a
thread-safe list.

Silvio Cl├ęcio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150214/6b0b7cf9/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FastCGI_Proxy_Apache24_II.zip
Type: application/zip
Size: 17088 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150214/6b0b7cf9/attachment.zip>

More information about the fpc-pascal mailing list