Skip to Content.
Sympa Menu

devel - [sympa-developpers] database connection pooling

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Guillaume Rousse <address@concealed>
  • To: address@concealed
  • Subject: [sympa-developpers] database connection pooling
  • Date: Mon, 10 Mar 2014 19:26:23 +0100

Le 06/03/2014 15:39, IKEDA Soji a écrit :
Developers,

I examine not to provide connection pooling and auto reconnect of
SDM, but I found it is very costy. So I restored that feature.
'pooling' usually means 'pre-allocating multiple instances of a given resource, to make it immediatly available on demand thereafter'. It makes sense in a web applications context, for instance, where the parent process takes care of creating multiple LDAP or database connection in a *shared* memory section, so as multiple children can subsequently retrieve and use them as needed. Given than the only concurrency context in Sympa (CGI or bulk daemon) relies on isolated processes, unable to share anything, I don't really see any significant interest for pooling the single database connection in use...

The only current benefit of this 'pooling' feature is to cache the database connection (the DBI::DBH instance), because it is lazily created as a side effect of any kind of database operation. Any call to any function in Sympa::DatabaseManager function, such as do_query(), will silently intialize this connection, relying on this caching mechanism to avoid creating duplicate DBI::DBH instances... I could summarize its purpose as "no need to worry where I should store my database handle, as I can throw it away in a loose bag after every usage, and dig this bag again next time I need it". Dubious feature...

A far simpler, readable and efficient solution would be to have each binary (sympa.pl, bulk.pl, wwwsympa.fcgi) explicitely create this database connection on startup, check if it is uptodate (otherwise, exit immediately), and keep a permanent reference on it, for later usage. Ie, something as:

# read configuration

our $database = Sympa::Database->new(%params);
croak 'unable to connect to the database, check your configuration'
if !$database->connect();
croak 'database need to be updated first, use sympa_wizard'
if !$database->up_to_date();

# let's assume than the database is now available and fonctional
# from this point everywhere in the code as $main::database


90% of code in Sympa::DatabaseManager would become immediatly useless, a they just forward function call to the underlying $db_source object.
--
Guillaume Rousse
INRIA, Direction des systèmes d'information
Domaine de Voluceau
Rocquencourt - BP 105
78153 Le Chesnay
Tel: 01 39 63 58 31

Attachment: smime.p7s
Description: Signature cryptographique S/MIME




Archive powered by MHonArc 2.6.19+.

Top of Page