[rt-users] Apache FastCGI and # of db connections

Václav Ovsík vaclav.ovsik at i.cz
Fri Jan 10 05:45:09 EST 2014


Hi,

Thanks very much for Request Tracker!

I have a question regarding behaviour of FastCGI processes and database
connections. While preparing upgrade of RT 3.8.16 to RT 4.2.1 I noticed
a change of FastCGI usage in the RT.

I am using Debian Wheezy (with some packages from Jessie/Sid to satisfy
dependencies) and PostgreSQL as database backend on it.

I have a four instances of RT connecting to one PostgreSQL server.
FastCGI processes of my old instances (3.8.16) was configured in the
Apache:

 FastCgiServer /opt/eu/bin/mason_handler.fcgi -idle-timeout 400 -processes 9 -init-start-delay 1
 FastCgiServer /opt/interni/bin/mason_handler.fcgi -idle-timeout 400 -processes 2 -init-start-delay 2
 FastCgiServer /opt/nis/bin/mason_handler.fcgi -idle-timeout 400 -processes 9 -init-start-delay 2
 FastCgiServer /opt/RT/bin/mason_handler.fcgi -idle-timeout 400 -processes 9 -init-start-delay 1

So I have a total number of 3 * 9 + 2 = 29 FastCGI processes and the
same number of database connections:

 rt=# select count(*) from pg_stat_activity where usename like 'rt_%';
  count 
 -------
     29
 (1 row)

Note: all RT DB accounts starts with `rt_'.

I have limited number of database connection on the server:
rt:~# grep ^max_connections /etc/postgresql/9.1/main/postgresql.conf
max_connections = 48                    # (change requires restart)

And this number (48) is sufficient so.


During testing of RT 4.2.1 instances on the testing box with modified
configuration according to web_deployment.pod I got after a while exhausted
database connections.
I noticed every FastCGI process forks one child (Placks default?), that
delays database connection to HTTP request time, so I ended up with two
times number of DB connections than before.

I tried to configure one fresh instance:

 <Directory "/opt/rt4-preview" >
     Options FollowSymLinks ExecCGI
     AllowOverride None
 </Directory>
 FastCgiServer /opt/rt4-preview/sbin/rt-server.fcgi -processes 5 -idle-timeout 300
 ScriptAlias /rt4 /opt/rt4-preview/sbin/rt-server.fcgi

this is according to docs/web_deployment.pod I hope.

During Apache startup, it is possible for a moment to see processes:
 \_ /usr/bin/perl -w /opt/rt4-preview/sbin/rt-server.fcgi
which quickly transforms into daemonized couple:
 \_ perl-fcgi-pm                                         
 |   \_ perl-fcgi                                            

After a while the situation is (pstree):
     ├─apache2─┬─apache2─┬─5*[perl-fcgi-pm───perl-fcgi]
     │         │         └─3*[rt-index.fcgi]
     │         └─5*[apache2]

Till no request is handled the connections are:
 zito=# select count(*) from pg_stat_activity where usename like 'rt_%';
  count 
 -------
      5
 (1 row)

The number of connections grows during requests on web interface and ends with:
zito=# select count(*) from pg_stat_activity where usename like 'rt_%';
 count 
-------
    10
(1 row)

All children processes are connected to database...

Is this setup really ok?

I did not study Plack too much - only look at
http://search.cpan.org/~miyagawa/Plack-1.0030/lib/Plack/Handler/FCGI.pm
and there is approach a bit different. One daemon is started standalone
(forking to a number of processes) and Apache is configured to connect
to this daemon
 FastCgiExternalServer /tmp/myapp.fcgi -socket /tmp/fcgi.sock

But I don't know technology.
Should I really increase PostgreSQL max_connections to 100 and don't
bother with it?
Best Regards
-- 
Zito



More information about the rt-users mailing list