Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 3C82713364DE for ; Sun, 10 Oct 2010 04:14:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 31494-04 for ; Sun, 10 Oct 2010 07:14:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 82CE61336473 for ; Sun, 10 Oct 2010 04:14:37 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 26728AF98F; Sun, 10 Oct 2010 15:14:36 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 4f+WuPgCCk38; Sun, 10 Oct 2010 15:14:30 +0800 (WST) Received: from [10.1.1.8] (124-148-209-200.dyn.iinet.net.au [124.148.209.200]) (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 ESMTPSA id A0229AEE65; Sun, 10 Oct 2010 15:14:29 +0800 (WST) Message-ID: <4CB167CA.9070109@postnewspapers.com.au> Date: Sun, 10 Oct 2010 15:14:18 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.12) Gecko/20100914 Thunderbird/3.0.8 MIME-Version: 1.0 To: mladen.gogala@vmsinfo.com CC: Neil Whelchel , "pgsql-performance@postgresql.org" Subject: Re: Slow count(*) again... References: <201010091626.18636.neil.whelchel@gmail.com> <4CB11CC7.8070300@vmsinfo.com> In-Reply-To: <4CB11CC7.8070300@vmsinfo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 X-Spam-Level: X-Archive-Number: 201010/87 X-Sequence-Number: 40506 On 10/10/2010 9:54 AM, Mladen Gogala wrote: > Unfortunately, the problem is in the rather primitive way PostgreSQL > does I/O. It didn't change in 9.0 so there is nothing you could gain by > upgrading. If you execute strace -o /tmp/pg.out -e read sequential scan process> and inspect the file /tmp/pg.out when the query > finishes, you will notice a gazillion of read requests, all of them 8192 > bytes in size. That means that PostgreSQL is reading the table block by > block, without any merging of the requests. I'd be really interested in any measurements you've done to determine the cost of this over doing reads in larger chunks. If they're properly detailed and thought out, the -hackers list is likely to be interested as well. The Linux kernel, at least, does request merging (and splitting, and merging, and more splitting) along the request path, and I'd personally expect that most of the cost of 8k requests would be in the increased number of system calls, buffer copies, etc required. Measurements demonstrating or contradicting this would be good to see. It's worth being aware that there are memory costs to doing larger reads, especially when you have many backends each of which want to allocate a larger buffer for reading. If you can use a chunk of shared_buffers as the direct destination for the read that's OK, but otherwise you're up for (1mb-8kb)*num_backends extra memory use on I/O buffers that could otherwise be used as shared_buffers or OS cache. Async I/O, too, has costs. > PostgreSQL is in > dire need of something similar and it wouldn't even be that hard to > implement. I'd really like to see both those assertions backed with data or patches ;-) Personally, I know just enough about how PG's I/O path works to suspect that "not that hard to implement" is probably a little ... over-optimistic. Sure, it's not that hard to implement in a new program with no wired-in architectural and design choices; that doesn't mean it's easy to retrofit onto existing code, especially a bunch of co-operating processes with their own buffer management. -- Craig Ringer Tech-related writing at http://soapyfrogs.blogspot.com/