Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dopSi-0005nr-IP for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Sep 2017 11:22:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dopSh-0006hz-Cu for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Sep 2017 11:22:39 +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.84_2) (envelope-from ) id 1dopR8-0003y0-SU for pgsql-hackers@postgresql.org; Mon, 04 Sep 2017 11:21:02 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dopR0-0001Nc-J2 for pgsql-hackers@postgresql.org; Mon, 04 Sep 2017 11:21:02 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 0B37121C091D; Mon, 4 Sep 2017 14:20:53 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from falcon-work (unknown [192.168.27.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id BA51D21C0552; Mon, 4 Sep 2017 14:20:52 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1504524052; bh=RndeB52vv8YRJUXS1tCqmFU07M7zZGOlleA8KnzqZck=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=HGijD8yJVZxOpSOBqh4rpGMk4Vhbh5fJx7+6lpLHUSxg+dXjDEaHib5jElcxObN0p 2CVRsJd3nYPoewRSKvq0VRpOsNcJdpRahdGp2zd8Z76OaCxTL6Hrnz3KRbU4BDpb2M Vesz1TxjkMOyHzS1AjTRBmcaso/weGuCGMbgoqYc= Date: Mon, 4 Sep 2017 14:20:52 +0300 From: Sokolov Yura To: Tom Lane , Robert Haas Cc: pgsql-hackers@postgresql.org, craig@2ndquadrant.com, Petr Jelinek Subject: Re: Walsender timeouts and large transactions Message-ID: <20170904142052.02203dda@falcon-work> In-Reply-To: References: <20170802173558.1342.32988.pgcf@coridan.postgresql.org> <6259a2a9-e683-c3a6-2da8-249b862d8099@2ndquadrant.com> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2017-05-25 17:52 Petr Jelinek wrote: > Hi, > > We have had issue with walsender timeout when used with logical > decoding and the transaction is taking long time to be decoded > (because it contains many changes) > > I was looking today at the walsender code and realized that it's > because if the network and downstream are fast enough, we'll always > take fast path in WalSndWriteData which does not do reply or > keepalive processing and is only reached once the transaction has > finished by other code. So paradoxically we die of timeout because > everything was fast enough to never fall back to slow code path. > > I propose we only use fast path if the last processed reply is not > older than half of walsender timeout, if it is then we'll force the > slow code path to process the replies again. This is similar logic > that we use to determine if to send keepalive message. I also added > CHECK_INTERRUPRS call to fast code path because otherwise walsender > might ignore them for too long on large transactions. > > Thoughts? > On 2017-08-10 14:20 Sokolov Yura wrote: > On 2017-08-09 16:23, Petr Jelinek wrote: > > On 02/08/17 19:35, Yura Sokolov wrote: > >> The following review has been posted through the commitfest > >> application: > >> make installcheck-world: tested, passed > >> Implements feature: not tested > >> Spec compliant: not tested > >> Documentation: not tested > >> > >> There is no check for (last_reply_timestamp <= 0 || > >> wal_sender_timeout <= 0) as in other places > >> (in WalSndKeepaliveIfNecessary for example). > >> > >> I don't think moving update of 'now' down to end of loop body is > >> correct: > >> there are calls to ProcessConfigFile with SyncRepInitConfig, > >> ProcessRepliesIfAny that can > >> last non-negligible time. It could lead to over sleeping due to > >> larger computed sleeptime. > >> Though I could be mistaken. > >> > >> I'm not sure about moving `if (!pg_is_send_pending())` in a body > >> loop after WalSndKeepaliveIfNecessary. > >> Is it necessary? But it looks harmless at least. > >> > > > > We also need to do actual timeout handing so that the timeout is not > > deferred to the end of the transaction (Which is why I moved `if > > (!pg_is_send_pending())` under WalSndCheckTimeOut() and > > WalSndKeepaliveIfNecessary() calls). > > > > If standby really stalled, then it will not read from socket, and then > `pg_is_sendpending` eventually will return false, and timeout will be > checked. > If standby doesn't stall, then `last_reply_timestamp` will be updated > in `ProcessRepliesIfAny`, and so timeout will not be triggered. > Do I understand correctly, or I missed something? > > >> Could patch be reduced to check after first `if > >> (!pg_is_sendpending())` ? like: > >> > >> if (!pq_is_send_pending()) > >> - return; > >> + { > >> + if (last_reply_timestamp <= 0 || > >> wal_sender_timeout <= 0) > >> + { > >> + CHECK_FOR_INTERRUPTS(); > >> + return; > >> + } > >> + if (now <= > >> TimestampTzPlusMilliseconds(last_reply_timestamp, > >> wal_sender_timeout / 2)) > >> + return; > >> + } > >> > >> If not, what problem prevents? > > > > We should do CHECK_FOR_INTERRUPTS() independently of > > pq_is_send_pending so that it's possible to stop walsender while > > it's processing large transaction. > > In this case CHECK_FOR_INTERRUPTS will be called after > wal_sender_timeout/2. > (This diff is for first appearance of `pq_is_send_pending` in a > function). > > If it should be called more often, then patch could be simplier: > > if (!pq_is_send_pending()) > - return; > + { > + CHECK_FOR_INTERRUPTS(); > + if (last_reply_timestamp <= 0 || wal_sender_timeout > <= 0 || > + now <= > TimestampTzPlusMilliseconds(last_reply_timestamp, > wal_sender_timeout / 2)) > + return; > + } > > (Still, I could be mistaken, it is just suggestion). > > Is it hard to add test for case this patch fixes? > > With regards, Tom, Robert, I believe this bug have to be fixed in Pg10, and I don't wonna be that guy who prevents it from being fixed. What should/could I do? ( https://commitfest.postgresql.org/14/1151/ ) -- With regards, Sokolov Yura aka funny_falcon Postgres Professional: https://postgrespro.ru The Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers