[Mapserver-dev] FastCGI Implementation / connection pooling
Sean Gillies
sgillies at frii.com
Thu Sep 23 16:19:48 EDT 2004
On Sep 23, 2004, at 11:53 AM, Frank Warmerdam wrote:
> Sean Gillies wrote:
>> Would you consider an approach that would support the use case of
>> mapscript
>> and shared connections? Python and Perl's DBI modules are based on
>> libpq,
>> so there is something in there that we can transform into a mapserver
>> postgis connection:
>> >>> dsn = "dbname=postgis"
>> >>> dbcon = psycopg.connect(dsn) # Python database connection
>> >>> postgis_layer.connect(dbcon) # use existing connection
>> I'm not asking you to write the code under such a layerObj::connect
>> method, just to not close the door on such a thing.
>
> Sean,
>
> I was thinking of maintaining a central connection pool and interfacing
> to it with a small set of mapserver functions. For each connection I
> would
> keep track of the connection type, the connection string, the handle
> and
> possibly some sort of "lifetime" indicator (whether it should be
> destroyed
> after processing map or kept alive till application termination) and a
> reference count.
>
> Exactly what the "handle" is will vary from connection type to
> connection
> type. For a PostGIS/PostgreSQL database the connection handle would
> presumably be the handle returned by PQconnectcb(). For OGR
> connections,
> it would be the OGRDataSourceH handle.
>
> I think it would make sense to expose this connection management API to
> mapScript, and then (hopefully) a mapscript application could
> "prepopulate"
> the connection pool. This would depend on some means to turn whatever
> "psycopg.connect()" returns into a proper C style pointer for the
> connection
> string of course. That might require a bit of custom glue for each
> connection type.
>
> I will keep this in mind, and perhaps we can work together to test it
> from
> MapScript.
>
Frank,
Sounds good, but in my case, I wouldn't be using your connection pool.
I'm more interested in using middleware such as pgpool, or twisted's
db pooling, or Zope's, or rolling my own.
I think that my need to connect a postgis layer directly to an open
database connection should be compatible with your pool. If your pool
were to contain instances of a "PgConnection" class (for example),
my use would be
dbcon = get_connection_from_pool() # Python database connection
pgcon = mapscript.PgConnection(dbcon) # wrap up for mapserver
postgis_layer.connect(pgcon)
postgis_layer.draw()
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the mapserver-dev
mailing list