Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gH8Dg-00062N-RR for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Oct 2018 14:08:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gH8De-0000gU-5S for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Oct 2018 14:08:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gH8Dd-0000gN-Ua for pgsql-hackers@lists.postgresql.org; Mon, 29 Oct 2018 14:08:37 +0000 Received: from mx1.mailbox.org ([2001:67c:2050:104:0:1:25:1]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gH8DX-0007TA-Dl for pgsql-hackers@postgresql.org; Mon, 29 Oct 2018 14:08:37 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 16192400BF; Mon, 29 Oct 2018 15:08:27 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id ZkzD6sDqcLig; Mon, 29 Oct 2018 15:08:25 +0100 (CET) From: Antonin Houska To: Kyotaro HORIGUCHI cc: andres@anarazel.de, magnus@hagander.net, robertmhaas@gmail.com, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org Subject: Re: shared-memory based stats collector In-reply-to: <20181005.173017.151015949.horiguchi.kyotaro@lab.ntt.co.jp> References: <20180926.095509.182252925.horiguchi.kyotaro@lab.ntt.co.jp> <20180927.220049.168546206.horiguchi.kyotaro@lab.ntt.co.jp> <20181002.160651.117284090.horiguchi.kyotaro@lab.ntt.co.jp> <20181005.173017.151015949.horiguchi.kyotaro@lab.ntt.co.jp> Comments: In-reply-to Kyotaro HORIGUCHI message dated "Fri, 05 Oct 2018 17:30:17 +0900." MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 29 Oct 2018 15:10:10 +0100 Message-ID: <28855.1540822210@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kyotaro HORIGUCHI wrote: > This is more saner version of previous v5-0008, which didn't pass > regression test. v6-0008 to v6-0010 are attached and they are > applied on top of v5-0001-0007. >=20 > - stats collector has been removed. >=20 > - modified dshash further so that deletion is allowed during > sequential scan. >=20 > - I'm not sure about the following existing comment at the > beginning of pgstat.c >=20 > * - Add a pgstat config column to pg_database, so this > * entire thing can be enabled/disabled on a per db basis. Following is the next handful of my comments: * If you remove the stats collector, I think the remaining code in pgstat.c does no longer fit into the backend/postmaster/ directory. * I'm not sure it's o.k. to call pgstat_write_statsfiles() from postmaster.c:reaper(): the function can raise ERROR (I see at least one c= ode path: pgstat_write_statsfile() -> get_dbstat_filename()) and, as reaper()= is a signal handler, it's hard to imagine the consequences. Maybe a reason to leave some functionality in a separate worker, although the "stats collector" would have to be changed. * Question still remains whether all the statistics should be loaded into shared memory, see the note on paging near the bottom of [1]. * if dshash_seq_init() is passed consistent=3Dfalse, shouldn't we call ensure_valid_bucket_pointers() also from dshash_seq_next()? If the scan needs to access the next partition and the old partition lock got release= d, the table can be resized before the next partition lock is acquired, and thus the backend-local copy of buckets becomes obsolete. * Neither snapshot_statentry_all() nor backend_snapshot_all_db_entries() se= ems to be used in the current patch version. * pgstat_initstats(): I think WaitLatch() should be used instead of sleep(). * pgstat_get_db_entry(): "return false" should probably be "return NULL". * Is the PGSTAT_TABLE_WRITE flag actually used? Unlike PGSTAT_TABLE_CREATE,= I couldn't find a place where it's value is tested. * dshash_seq_init(): does it need to be called with consistent=3Dtrue from pgstat_vacuum_stat() when the the entries returned by the scan are just dropped? dshash_seq_init(&dshstat, db_stats, true, true); I suspect this is a thinko because another call from the same function looks like dshash_seq_init(&dshstat, dshtable, false, true); * I'm not sure about usefulness of dshash_get_num_entries(). It passes consistent=3Dfalse to dshash_seq_init(), so the number of entries can cha= nge during the execution. And even if the function requested a "consistent scan", entries can be added / removed as soon as the scan is over. If the returned value is used to decide whether the hashtable should be scanned or not, I think you don't break anything if you simply start the scan unconditionally and see if you find some entries. And if you really need to count the entries, I suggest that you use the per-partition counts (dshash_partition.count) instead of scanning individ= ual entries. [1] https://www.postgresql.org/message-id/CA+TgmobQVbz4K_+RSmiM9HeRKpy3vS5x= nbkL95gSEnWijzprKQ@mail.gmail.com --=20 Antonin Houska Cybertec Sch=C3=B6nig & Sch=C3=B6nig GmbH Gr=C3=B6hrm=C3=BChlgasse 26, A-2700 Wiener Neustadt Web: https://www.cybertec-postgresql.com