Hi all,

I was just going thr. the ecpg sources checking for thread safety. 

It looks like the mutex protects the connections list in connection.c. I do 
not like that from a application developers perspective.

If I am developing an application and using multiple connections in multiple 
threads, I have to store a connection name for each connection as C string. 
Of course, I also have to protect it across thread so that I can rightly tell 
ecpg what connection I would be talking to next.

If an application can take care of a C string, it can also take care of a 
connection structure. On top of it, it eliminates the list lookup. The 
potential performance gain could be worth it if there are hundreds of 
connections and a busy website/application server.

What I wonder is, do we really need to maintain that level of lookup? Can't we 
just say a connection is a 'struct connection *' which should be opaque and 
should not be touched or poked inside, just like PGConn.

Just a thought... 

 Shridhar

Mon, 23 Feb 2004 21:27:40 +0530
Shridhar Daithankar <shridhar@frodo.hserus.net>
Thread safe connection-name mapping in ECPG. Is it required?
On Mon, Feb 23, 2004 at 09:27:40PM +0530, Shridhar Daithankar wrote:
> It looks like the mutex protects the connections list in connection.c. I do 
> not like that from a application developers perspective.
> 
> If I am developing an application and using multiple connections in multiple 
> threads, I have to store a connection name for each connection as C string. 
> Of course, I also have to protect it across thread so that I can rightly tell 
> ecpg what connection I would be talking to next.
> 
> If an application can take care of a C string, it can also take care of a 
> connection structure. On top of it, it eliminates the list lookup. The 
> potential performance gain could be worth it if there are hundreds of 
> connections and a busy website/application server.
> 
> What I wonder is, do we really need to maintain that level of lookup? Can't we 
> just say a connection is a 'struct connection *' which should be opaque and 
> should not be touched or poked inside, just like PGConn.

I'm not sure I understand you correctly. The SQL standard says you can
call your statement as this:
exec sql at CONNECTION select 1;

Here CONNECTION of course is a string, the name of the connection. So,
yes, we have to maintain that list to make sure we get the right
connection.

Or what were you asking?

Michael
-- 
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!

Fri, 27 Feb 2004 08:39:13 +0100
Michael Meskes <meskes@postgresql.org>
Re: Thread safe connection-name mapping in ECPG. Is it required?
Michael Meskes wrote:
> On Mon, Feb 23, 2004 at 09:27:40PM +0530, Shridhar Daithankar wrote:
>>What I wonder is, do we really need to maintain that level of lookup? Can't we 
>>just say a connection is a 'struct connection *' which should be opaque and 
>>should not be touched or poked inside, just like PGConn.
> I'm not sure I understand you correctly. The SQL standard says you can
> call your statement as this:
> exec sql at CONNECTION select 1;
> 
> Here CONNECTION of course is a string, the name of the connection. So,
> yes, we have to maintain that list to make sure we get the right
> connection.
> 
> Or what were you asking?

I am asking for CONNECTION being a variable of data type 'connection *' rather 
than 'const char *'. That would avoid name lookups.

Is that out of spec?

  Shridhar

Fri, 27 Feb 2004 15:02:22 +0530
Shridhar Daithankar <shridhar@frodo.hserus.net>
Re: Thread safe connection-name mapping in ECPG. Is it