Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cHph9-0004Yk-O3 for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Dec 2016 10:24:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cHph8-0001Kx-E1 for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Dec 2016 10:24:54 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cHph7-0001Kq-5L for pgsql-hackers@postgresql.org; Fri, 16 Dec 2016 10:24:53 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cHpgz-0006wd-6U for pgsql-hackers@postgresql.org; Fri, 16 Dec 2016 10:24:51 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 7C23642D4E for ; Fri, 16 Dec 2016 11:24:41 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTPS id wHwRA0NxXALa for ; Fri, 16 Dec 2016 11:24:33 +0100 (CET) From: Antonin Houska To: pgsql-hackers@postgresql.org Subject: Re: Slow I/O can break throttling of base backup In-reply-to: <10526.1481818893@localhost> References: <10526.1481818893@localhost> Comments: In-reply-to Antonin Houska message dated "Thu, 15 Dec 2016 17:21:33 +0100." MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Fri, 16 Dec 2016 11:24:30 +0100 Message-ID: <27929.1481883870@localhost> X-Pg-Spam-Score: -2.6 (--) 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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Antonin Houska wrote: > It seems to be my bug. I'll check tomorrow. I could reproduce the problem by adding sufficient sleep time to the loop. > Magnus Hagander wrote: >> I wonder if the else if (sleep > 0) at the bottom of throttle() should j= ust >> be a simple else and always run, resetting last_throttle? I agree. In fact, I could simplify the code even more. Since (elapsed + sleep) almost equals to GetCurrentIntegerTimestamp(), we c= an use the following statement unconditionally (I think I tried too hard to av= oid calling GetCurrentIntegerTimestamp too often in the original patch): throttled_last =3D GetCurrentIntegerTimestamp(); Thus we can also get rid of the "else" branch that clears both "sleep" and "wait_result". (The patch contains minor comment refinement that I found useful when seeing the code after years.) --=20 Antonin Houska Cybertec Sch=C3=B6nig & Sch=C3=B6nig GmbH Gr=C3=B6hrm=C3=BChlgasse 26 A-2700 Wiener Neustadt Web: http://www.postgresql-support.de, http://www.cybertec.at --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=throttling.patch diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c new file mode 100644 index ffc7e58..40b3c11 *** a/src/backend/replication/basebackup.c --- b/src/backend/replication/basebackup.c *************** throttle(size_t increment) *** 1370,1395 **** if (wait_result & WL_LATCH_SET) CHECK_FOR_INTERRUPTS(); } - else - { - /* - * The actual transfer rate is below the limit. A negative value - * would distort the adjustment of throttled_last. - */ - wait_result = 0; - sleep = 0; - } /* ! * Only a whole multiple of throttling_sample was processed. The rest will ! * be done during the next call of this function. */ throttling_counter %= throttling_sample; ! /* Once the (possible) sleep has ended, new period starts. */ ! if (wait_result & WL_TIMEOUT) ! throttled_last += elapsed + sleep; ! else if (sleep > 0) ! /* Sleep was necessary but might have been interrupted. */ ! throttled_last = GetCurrentIntegerTimestamp(); } --- 1370,1385 ---- if (wait_result & WL_LATCH_SET) CHECK_FOR_INTERRUPTS(); } /* ! * As we work with integers, only whole multiple of throttling_sample was ! * processed. The rest will be done during the next call of this function. */ throttling_counter %= throttling_sample; ! /* ! * Time interval for the remaining amount and possible next increments ! * starts now. ! */ ! throttled_last = GetCurrentIntegerTimestamp(); } --=-=-= Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --=-=-=--