Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 8A8701337B9E for ; Wed, 22 Dec 2010 04:32:26 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 95168-02 for ; Wed, 22 Dec 2010 08:32:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 64.mail-out.ovh.net (64.mail-out.ovh.net [91.121.185.65]) by mail.postgresql.org (Postfix) with SMTP id 3B7261337B56 for ; Wed, 22 Dec 2010 04:32:17 -0400 (AST) Received: (qmail 3502 invoked by uid 503); 22 Dec 2010 08:05:39 -0000 Received: from b9.ovh.net (HELO mail411.ha.ovh.net) (213.186.33.59) by 64.mail-out.ovh.net with SMTP; 22 Dec 2010 08:05:39 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 22 Dec 2010 10:22:18 +0200 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 22 Dec 2010 10:22:18 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Pavel Stehule" , "Michael Ben-Nes" Cc: "PostgreSQL Performance" Subject: Re: MySQL HandlerSocket - Is this possible in PG? References: Date: Wed, 22 Dec 2010 09:22:17 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: User-Agent: Opera Mail/10.63 (Linux) X-Ovh-Tracer-Id: 13058750071522264664 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201012/274 X-Sequence-Number: 41726 > Do you mean I should use PREPARE? > > Currently I use PHP to access the DB which use libpq. Is that cosidered a > fast call API ? if not, can you please refer me to the right info. > > PHP pg_pconnect command open a persistent PostgreSQL connection. Is it > enough or I better use PgPool2 or something similar? > > Considering the points above, will I be able to get such high QPS from > PostgreSQL ? If so, it will be my pleasure to dump Reddis and work solely > with PG :) I suppose you already have a web server like lighttpd, zeus, or nginx, using php as fastcgi, or apache behind a proxy ? In that case, since the number of php processes is limited (usually to something like 2x your number of cores), the number of postgres connections a web server generates is limited, and you can do without pgpool and use pg_pconnect. Be wary of the pg_pconnect bugs though (like if you restart pg, you also have to restart php, I suppose you know that). Here are some timings (Core 2 Q6600) for a simple SELECT on PK query : using tcp (localhost) 218 µs / query : pg_query 226 µs / query : pg_query_params 143 µs / query : pg_execute using unix sockets 107 µs / query : pg_query 122 µs / query : pg_query_params 63 µs / query : pg_execute query inside plpgsql function 17 µs / query Don't use PDO, it is 2x-3x slower. TCP overhead is quite large... If you have a named prepared statement (created with PREPARE) use pg_execute(), which is much faster than pg_query (for very simple queries). Of course you need to prepare the statements... you can do that with pg_pool which can execute a script upon connection initialization.