Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xtpjs-0005rS-O4 for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Nov 2014 03:27:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xtpjs-0003xE-0v for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Nov 2014 03:27:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xtpjr-0003x0-0N for pgsql-bugs@postgresql.org; Thu, 27 Nov 2014 03:27:27 +0000 Received: from smtp-out1.gransy.com ([77.78.126.51]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xtpji-0005P6-UK for pgsql-bugs@postgresql.org; Thu, 27 Nov 2014 03:27:25 +0000 Received: from smtp-out.gransy.com (localhost [127.0.0.1]) by smtp-out1.gransy.com (Postfix) with ESMTP id BE1EC360038 for ; Thu, 27 Nov 2014 04:27:16 +0100 (CET) Received: from smtp.gransy.com (smtp.simplia.cz [77.78.126.20]) by smtp-out1.gransy.com (Postfix) with ESMTP id 6E59E360005 for ; Thu, 27 Nov 2014 04:27:16 +0100 (CET) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz [78.45.139.138]) (Authenticated sender: tv@fuzzy.cz) by smtp.gransy.com (Postfix) with ESMTPSA id 31AF419A0440 for ; Thu, 27 Nov 2014 04:27:15 +0100 (CET) Message-ID: <54769A13.50408@fuzzy.cz> Date: Thu, 27 Nov 2014 04:27:15 +0100 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #12071: Stat collector went crasy (50MB/s constant writes) References: <20141126130810.15507.39189@wrigleys.postgresql.org> <54763BD8.8020906@fuzzy.cz> <54764BF6.20605@fuzzy.cz> <5476539A.6090506@fuzzy.cz> <54766086.6090205@fuzzy.cz> In-Reply-To: <54766086.6090205@fuzzy.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 27.11.2014 00:21, Tomas Vondra wrote: > On 27.11.2014 00:01, Maxim Boguk wrote: >> >> >> On Thu, Nov 27, 2014 at 1:26 AM, Tomas Vondra > > wrote: >> >> On 26.11.2014 23:06, Maxim Boguk wrote: >> > >> > >> > I'm not sure I understand what you mean. >> > >> > The timestamp *IS* updated on every write - see this: >> > >> > https://github.com/postgres/postgres/blob/REL9_2_STABLE/src/backend/postmaster/pgstat.c#L3469 >> > >> > >> > I mean that usually 99.9% writes goes through mmap, which update the >> > pgstat.tmp file timestamp (but not update last_statwrite value). >> >> I don't follow. Can you explain what you mean by the mmap? I don't see >> any mmap stuff in pgstat.c, nor I remember dealing with mmap in my >> patches in this area ... >> >> >> Hm I had been wrong. I seen mmap call on strace after every statistic >> collector file rewrite and I thought that all writes to that file goes >> through memory mapped structure instead of full file writes every time >> when someone need fresh data. >> >> However, point still open - there are no reason to write a new file >> from scratch if no activity had been received from stat socket since >> the last write (the same point valid for per-database stat files in >> 9.3+). > > Well, nothing is perfect and patches are always welcome ;-) > > For us, the per-db split was enough - it lowered the CPU and I/O load to > the point that adding such 'is dirty' flag would make absolutely no > difference. I do have it on my TODO list, but it's not very high. FWIW, I got curious and checked why we decided not to implement this while reworking the stats in 9.3, as keeping an is_dirty flag seems as a rather straightforward and simple optimization. Turns out it's actually considerably more complex, because one of the sources of statistics updates are (surprise surprise) autovacuum workers. So the whole flow may look like this (in >= 9.3): 1) launcher requests a fresh stats file (dbs list only) 2) worker is started for a particular DB (by launcher) 3) the worker requests a stats file (with details for the DB) 4) the worker vacuums the DB - scans pg_class etc., updates the table stats (autovac timestamps, blocks/tuples read ...) 5) at worker shutdown, the stats are sent back to postmaster So this dirties the stats file (written in 3) for the database, making the file obsolete. Now, there are two choices - you may immediately flush the changes to disk (but maybe you'll receive more changes before the next autovacuum round happens), or you wait and only write the file if requested (which is what we do now). So the file *IS* dirty, and I don't see any obvious solution to this :-( Tomas -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs