Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtc9n-0003yM-45 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Feb 2019 17:47:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtc9l-0006RL-GN for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Feb 2019 17:47:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtc9l-0006R9-0g for pgsql-hackers@lists.postgresql.org; Tue, 12 Feb 2019 17:47:41 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtc9h-0006rq-H4 for pgsql-hackers@lists.postgresql.org; Tue, 12 Feb 2019 17:47:39 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id F1B2321CCD1E; Tue, 12 Feb 2019 20:47:34 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.0.105] (unknown [5.79.140.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 9D64821CCD17; Tue, 12 Feb 2019 20:47:34 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1549993654; bh=IixOBEmVF3/uRq9iUg2SmGd69QQbUQ/6wFFzc9qG5Ig=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=MUffCxjfUsXMolXmm9WPryclxyuRqqDl/w+73qhmy/A90sB69WZYAzOMCtrOwYyRL AyDL3sOGKjX/UP+yClnQUfz2EpWkKYYK8By8O251dUzHC6HHAUWQzlTZ1sayIJvVxx 4E24HarhBRytocbnQeSrKCOUT+eCt0tfP5FjIwbo= Subject: Re: [PATCH] xlogreader: do not read a file block twice To: Arthur Zakirov , pgsql-hackers@lists.postgresql.org Cc: Grigory Smolkin References: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: <93d74870-3217-7ab3-b220-31cab64b7c7a@postgrespro.ru> Date: Tue, 12 Feb 2019 22:47:32 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11.02.2019 21:25, Arthur Zakirov wrote: > Hello hackers, > > Grigory noticed that one of our utilities has very slow performance when > xlogreader reads zlib archives. We found out that xlogreader sometimes > reads a WAL file block twice. > > zlib has slow performance when you read an archive not in sequential > order. I think reading a block twice in same position isn't sequential, > because gzread() moves current position forward and next call gzseek() > to the same position moves it back. > > It seems that the attached patch solves the issue. I think when reqLen > == state->readLen the requested block already is in the xlogreader's > buffer. > > What do you think? I looked at the history of the code changes: --------------------------------------------------------------- 7fcbf6a405f (Alvaro Herrera 2013-01-16 16:12:53 -0300 539) reqLen < state->readLen) 1bb2558046c (Heikki Linnakangas 2010-01-27 15:27:51 +0000 9349) targetPageOff == readOff && targetRecOff < readLen) eaef111396e (Tom Lane 2006-04-03 23:35:05 +0000 3842) len = XLOG_BLCKSZ - RecPtr->xrecoff % XLOG_BLCKSZ; 4d14fe0048c (Tom Lane 2001-03-13 01:17:06 +0000 3843) if (total_len > len) --------------------------------------------------------------- In the original code of Tom Lane, condition (total_len > len) caused a page reread from disk. As I understand it, this is equivalent to your proposal. Th code line in commit 1bb2558046c seems tantamount to the corresponding line in commit 7fcbf6a405f but have another semantics: the targetPageOff value can't be more or equal XLOG_BLCKSZ, but the reqLen value can be. It may be a reason of appearance of possible mistake, introduced by commit 7fcbf6a405f. -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company