Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 69B36B5DBFB for ; Mon, 10 Oct 2011 12:39:17 -0300 (ADT) 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 34373-04 for ; Mon, 10 Oct 2011 15:39:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from smtp.peak6.com (smtp.peak6.com [38.98.137.6]) by mail.postgresql.org (Postfix) with ESMTP id 4C1F2B5DBF2 for ; Mon, 10 Oct 2011 12:39:10 -0300 (ADT) X-AuditID: 0a64cb1e-b7c21ae0000074d4-9e-4e93119761e5 Message-ID: <4E93119C.8090407@peak6.com> Date: Mon, 10 Oct 2011 10:39:08 -0500 From: Shaun Thomas Reply-To: Organization: Peak6 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Leonardo Francalanci CC: alexandre - aldeia digital , "pgsql-performance@postgresql.org" Subject: Re: Adding more memory = hugh cpu load References: <4E92F294.9010405@gmail.com> <4E92FB87.1030703@peak6.com> <1318259675.10344.YahooMailNeo@web29011.mail.ird.yahoo.com> In-Reply-To: <1318259675.10344.YahooMailNeo@web29011.mail.ird.yahoo.com> Content-Type: text/plain; charset="UTF-8"; format=flowed content-transfer-encoding: 7bit X-Originating-IP: [10.10.220.61] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDIsWRmVeSWpSXmKPExsXCxcQrpjtDcLKfwcKljBYNf+4wWrS9SrK4 PvMcswOzx85Zd9k9Luybxu6x79Mn1gDmqAZGm8S8vPySxJJUhZTU4mRbpQBXR28zheCSxLyU xKIUBZfM4uScxMzc1CIlhcwUWyUjJYWCnMTk1NzUvBJbpcSCgtS8FCU7LgUMYANUlpmnkJqX nJ+SmZduq+QZ7K9rYWFqqWuoZBePAAndLBnTzu1mK1gpUfGj/ydTA+Nx4S5GTg4JAROJnpm3 mSBsMYkL99azgdi8AhoSV7bcBLI5OFgEVCWmbBEBCbMJqEks3H2TEcQWEpCV2L/qHCuIzS8g LLHvQxMziC0qECCxYNJbRogxghInZz5hAbFFBLQlfi//DBZnFqiRWHz6DVi9sIClxIHvPUBz uIBmNjJKXNixkAVkL6eAh8T1B+YQ9RYSi98cZIew5SW2v53DDHGDnMSdhudgZ0oIKEhcX+4/ gVFoFpLNs5B0z0LSvYCReRWjeHFZYnJGpmlBcW5JgaFeQWpitpleXmrJJkZQHKecltvBOH2p 4iFGAQ5GJR7eic6T/IRYE8uKK3MPMUpwMCuJ8Fb+AArxpiRWVqUW5ccXleakFh9i1AaG2ERm Ke7kfGCKySuJNzYwUBLnvc1c6yckkA5MAtmpqQWpRTDVTBycUg2MUpnyle9MNBce1OSP6fHb /vm2kebc8l+zpS6JNtRVT5q1ZMPGajGWdeV/d7RcU7h8Nvft++gEhy03p+b+z0vu0br9cqam 6NaC4B/KzWVH5dpnLhP43lpiOCM/2qJqc1T+/09Pls3iVtn7cqfVzNdujJ4CWbYVPCKMC0v2 9wYd2MYxmSM09lCOEktxRqKhFnNRcSIADFEweu8CAAA= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201110/81 X-Sequence-Number: 45303 On 10/10/2011 10:14 AM, Leonardo Francalanci wrote: > I don't understand: don't you want postgresql to issue the fsync > calls when it "makes sense" (and configure them), rather than having > the OS decide when it's best to flush to disk? That is: don't you > want all the memory to be used for caching, unless postgresql says > otherwise (calling fsync), instead of "as soon as 1% of memory is > used"? You'd think that, which is why this bites so many people. That's not quite how it works in practice, though. OS cache is a lot more than altered database and WAL files, which do get fsync'd frequently. Beyond that, you need to worry about what happens *between* fsync calls. On a highly loaded database, or even just a database experiencing heavy write volume due to some kind of ETL process, your amount of dirty memory may increase much more quickly than you expect. For example, say your checkpoint_timeout setting is the default of five minutes. An ETL process runs that loads 2GB of data into a table, and you're archiving transaction logs. So you now have three possible write vectors, not including temp tables and what not. And that's only for that connection; this gets more complicated if you have other OLTP connections on the same DB. So your memory is now flooded with 2-6GB of data, and that's easy for memory to handle, and it can do so quickly. With 48GB of RAM, that's well within caching range, so the OS never writes anything until the fsync call. Then the database makes the fsync call, and suddenly the OS wants to flush 2-6GB of data straight to disk. Without that background trickle, you now have a flood that only the highest-end disk controller or a backing-store full of SSDs or PCIe NVRAM could ever hope to absorb. That write flood massively degrades your read IOPS, and degrades future writes until it's done flushing, so all of your disk IO is saturated, further worsening the situation. Now you're getting closer and closer to your dirty_ratio setting, at which point the OS will effectively stop responding to anything, so it can finally finish flushing everything to disk. This can take a couple minutes, but it's not uncommon for these IO storms to last over half an hour depending on the quality of the disks/controller in question. During this time, system load is climbing precipitously, and clients are getting query timeouts. Adding more memory can actually make your system performance worse if you don't equally increase the capability of your RAID/SAN/whatever to compensate for increased size of write chunks. This is counter-intuitive, but completely borne out by tests. The kernel developers agree, or we wouldn't have dirty_bytes, or dirty_background_bytes, and they wouldn't have changed the defaults to 5% and 10% instead of 10% and 40%. It's just one of those things nobody expected until machines with vast amounts of RAM started becoming common. -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@peak6.com ______________________________________________ See http://www.peak6.com/email-disclaimer/ for terms and conditions related to this email