Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHLxW-00010u-DL for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Mar 2021 07:30:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lHLxV-00034S-Ah for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Mar 2021 07:30:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHLxV-00034I-3p for pgsql-hackers@lists.postgresql.org; Wed, 03 Mar 2021 07:30:13 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHLxS-0002MT-7e for pgsql-hackers@postgresql.org; Wed, 03 Mar 2021 07:30:12 +0000 Received: from hnk.local (p2386004-ipbf1026funabasi.chiba.ocn.ne.jp [118.6.4.4]) by oss.nttdata.com (Postfix) with ESMTPSA id 1391862728; Wed, 3 Mar 2021 16:30:05 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: About to add WAL write/fsync statistics to pg_stat_wal view To: Masahiro Ikeda Cc: "David G. Johnston" , PostgreSQL-development , Masahiko Sawada , Li Japin , kuroda.hayato@fujitsu.com References: <0509ad67b585a5b86a83d445dfa75392@oss.nttdata.com> <8555ab589d74ec2df61237209f4f21f2@oss.nttdata.com> <95c26651303d0e5227cb763061cf15dc@oss.nttdata.com> <395f109540835fabe76dbd9d45733a14@oss.nttdata.com> <925e940a832e96ca5d7276a4cc3dec83@oss.nttdata.com> <3df6e23e3e1e9cd95b08c943ef320046@oss.nttdata.com> <23a9f71817f616135551e2fde5ef362e@oss.nttdata.com> <930cae989a0fe8db6870cbeb5f24cf97@oss.nttdata.com> From: Fujii Masao Message-ID: <9a70efda-6f47-8b1c-0513-419e1185000a@oss.nttdata.com> Date: Wed, 3 Mar 2021 16:30:04 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <930cae989a0fe8db6870cbeb5f24cf97@oss.nttdata.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021/03/03 14:33, Masahiro Ikeda wrote: > On 2021-02-24 16:14, Fujii Masao wrote: >> On 2021/02/15 11:59, Masahiro Ikeda wrote: >>> On 2021-02-10 00:51, David G. Johnston wrote: >>>> On Thu, Feb 4, 2021 at 4:45 PM Masahiro Ikeda >>>> wrote: >>>> >>>>> I pgindented the patches. >>>> >>>> ... XLogWrite, which is invoked during an >>>> XLogFlush request (see ...).  This is also >>>> incremented by the WAL receiver during replication. >>>> >>>> ("which normally called" should be "which is normally called" or >>>> "which normally is called" if you want to keep true to the original) >>>> You missed the adding the space before an opening parenthesis here and >>>> elsewhere (probably copy-paste) >>>> >>>> is ether -> is either >>>> "This parameter is off by default as it will repeatedly query the >>>> operating system..." >>>> ", because" -> "as" >>> >>> Thanks, I fixed them. >>> >>>> wal_write_time and the sync items also need the note: "This is also >>>> incremented by the WAL receiver during replication." >>> >>> I skipped changing it since I separated the stats for the WAL receiver >>> in pg_stat_wal_receiver. >>> >>>> "The number of times it happened..." -> " (the tally of this event is >>>> reported in wal_buffers_full in....) This is undesirable because ..." >>> >>> Thanks, I fixed it. >>> >>>> I notice that the patch for WAL receiver doesn't require explicitly >>>> computing the sync statistics but does require computing the write >>>> statistics.  This is because of the presence of issue_xlog_fsync but >>>> absence of an equivalent pg_xlog_pwrite.  Additionally, I observe that >>>> the XLogWrite code path calls pgstat_report_wait_*() while the WAL >>>> receiver path does not.  It seems technically straight-forward to >>>> refactor here to avoid the almost-duplicated logic in the two places, >>>> though I suspect there may be a trade-off for not adding another >>>> function call to the stack given the importance of WAL processing >>>> (though that seems marginalized compared to the cost of actually >>>> writing the WAL).  Or, as Fujii noted, go the other way and don't have >>>> any shared code between the two but instead implement the WAL receiver >>>> one to use pg_stat_wal_receiver instead.  In either case, this >>>> half-and-half implementation seems undesirable. >>> >>> OK, as Fujii-san mentioned, I separated the WAL receiver stats. >>> (v10-0002-Makes-the-wal-receiver-report-WAL-statistics.patch) >> >> Thanks for updating the patches! >> >> >>> I added the infrastructure code to communicate the WAL receiver stats messages between the WAL receiver and the stats collector, and >>> the stats for WAL receiver is counted in pg_stat_wal_receiver. >>> What do you think? >> >> On second thought, this idea seems not good. Because those stats are >> collected between multiple walreceivers, but other values in >> pg_stat_wal_receiver is only related to the walreceiver process running >> at that moment. IOW, it seems strange that some values show dynamic >> stats and the others show collected stats, even though they are in >> the same view pg_stat_wal_receiver. Thought? > > OK, I fixed it. > The stats collected in the WAL receiver is exposed in pg_stat_wal view in v11 patch. Thanks for updating the patches! I'm now reading 001 patch. + /* Check whether the WAL file was synced to disk right now */ + if (enableFsync && + (sync_method == SYNC_METHOD_FSYNC || + sync_method == SYNC_METHOD_FSYNC_WRITETHROUGH || + sync_method == SYNC_METHOD_FDATASYNC)) + { Isn't it better to make issue_xlog_fsync() return immediately if enableFsync is off, sync_method is open_sync or open_data_sync, to simplify the code more? + /* + * Send WAL statistics only if WalWriterDelay has elapsed to minimize + * the overhead in WAL-writing. + */ + if (rc & WL_TIMEOUT) + pgstat_send_wal(); On second thought, this change means that it always takes wal_writer_delay before walwriter's WAL stats is sent after XLogBackgroundFlush() is called. For example, if wal_writer_delay is set to several seconds, some values in pg_stat_wal would be not up-to-date meaninglessly for those seconds. So I'm thinking to withdraw my previous comment and it's ok to send the stats every after XLogBackgroundFlush() is called. Thought? Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION