Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A84332E002C for ; Mon, 24 Mar 2008 04:58:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 67604-09 for ; Mon, 24 Mar 2008 04:58:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by postgresql.org (Postfix) with ESMTP id C03C72E0037 for ; Mon, 24 Mar 2008 04:58:28 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id 87BC5D55B2; Mon, 24 Mar 2008 16:58:21 +0900 (WST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 403261E0435; Mon, 24 Mar 2008 16:58:22 +0900 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ia56N4hu4aJm; Mon, 24 Mar 2008 16:58:20 +0900 (WST) Received: from [203.161.97.213] (203.161.97.213.static.amnet.net.au [203.161.97.213]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTP id 7B2301E0434; Mon, 24 Mar 2008 16:58:20 +0900 (WST) Message-ID: <47E75F18.9060206@postnewspapers.com.au> Date: Mon, 24 Mar 2008 16:58:16 +0900 From: Craig Ringer User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: firerox@centrum.cz Cc: pgsql-performance@postgresql.org Subject: Re: slow pg_connect() References: <200803240840.8128@centrum.cz> In-Reply-To: <200803240840.8128@centrum.cz> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=windows-1250; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/437 X-Sequence-Number: 29391 firerox@centrum.cz wrote: > It takes more then 0.05s :( > > Only this function reduce server speed max to 20request per second. > If you need that sort of frequent database access, you might want to look into: - Doing more work in each connection and reducing the number of connections required; - Using multiple connections in parallel; - Pooling connections so you don't need to create a new one for every job; - Using a more efficient database connector and/or language; - Dispatching requests to a persistent database access provider that's always connected However, your connections are indeed taking a long time. I wrote a trivial test using psycopg for Python and found that the following script: #!/usr/bin/env python import psycopg conn = pyscopg.connect("dbname=testdb") generally took 0.035 seconds (350ms) to run on my workstation - including OS process creation, Python interpreter startup, database interface loading, connection, disconnection, and process termination. A quick timing test shows that the connection/disconnection can be performed 100 times in 1.2 seconds: import psycopg import timeit print timeit.Timer('conn = psycopg.connect("dbname=craig")', 'import psycopg').timeit(number=100); ... and this is still with an interpreted language. I wouldn't be too surprised if much better again could be achieved with the C/C++ APIs, though I don't currently feel the desire to write a test for that. -- Craig Ringer