Re: libpq WSACleanup is not needed

From: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Jeroen Vermeulen <jtv(at)xs4all(dot)nl>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: libpq WSACleanup is not needed
Date: 2009-01-20 22:40:09
Message-ID: 497652C9.8060708@mansionfamily.plus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Chernow wrote:
> The only problem is how to detect the first connection. In a threaded
> environment you'd have to perform locking in connectdb, which is
> probably not going to fly.
Well, if you do an atomic test for a flag being zero, and if so then
enter a critsec, do
the init iff you're the first in, and then set the flag on the way out,
then:
- most times, you'll just have the atomic test
- other times, you have a short critsec

I can't see that being a big deal considering you're about to resolve
the server hostname
and then do a TCP/IP connect.

My understanding is that if you do WSAStartup and WSACleanup scoped to
each connection
then:
- the internal counting means that only the 0 -> 1 and 1 -> 0
transitions are expensive
- libpq will only incur the cost if the application didn't do it already

So it seems that the cost is incurred by an application that:
- makes no other use of winsock (or also does startup/cleanup often)
- does not retain a connection (or pool) but creates and closes
a single connection often

How many applications are there that match this pattern? Isn't it
enough just to tell
the user to do WSAStartup and WSACleanup in main() if they find they
have a performance problem? Surely most Windows programs effectively do
that
anyway, often as a side effect of using a framework.

James

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2009-01-20 22:40:34 Re: New pg_dump patch, --no-stats flag, disables sending to statistics collector
Previous Message Bryce Nesbitt 2009-01-20 22:15:44 Re: New pg_dump patch, --no-stats flag, disables sending to statistics collector