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 1gtEOy-0000gD-1T for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Feb 2019 16:25:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtEOu-0003Ki-Kb for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Feb 2019 16:25:44 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtEOu-0003KL-8t for pgsql-hackers@lists.postgresql.org; Mon, 11 Feb 2019 16:25:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtEOr-0000UU-Dc for pgsql-hackers@lists.postgresql.org; Mon, 11 Feb 2019 16:25:43 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 7D72621C7BA4; Mon, 11 Feb 2019 19:25:40 +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.27.237] (gw.postgrespro.ru [93.174.131.141]) (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 45E8C21C7B17; Mon, 11 Feb 2019 19:25:40 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1549902340; bh=HqnfqlLbYZt59fT5DIKsARnS+ThL5i+fV1KTp2NuRlA=; h=To:Cc:From:Subject:Date; b=LvW1Yni63QhAIQCYL41y1jtUZ78xHA+LwLrTPgGvdBBl/ZvLpe5hiJZY0Jc01VUfu vxesBOk4Gk3mk9VnLH5bpoKvQnuCvjsUsxVOgYxc1g3VahdPEMGEijnrjLZ/8cox8e Li5l2HQKjl01g4WU6Ik47MimkpVQSzYbhS0XJ6hM= To: pgsql-hackers@lists.postgresql.org Cc: Grigory Smolkin From: Arthur Zakirov Subject: [PATCH] xlogreader: do not read a file block twice Message-ID: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru> Date: Mon, 11 Feb 2019 19:25:39 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1F92CF77D83EF3F8A4B8F2C7" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------1F92CF77D83EF3F8A4B8F2C7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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? -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company --------------1F92CF77D83EF3F8A4B8F2C7 Content-Type: text/x-patch; name="xlogreader-reqlen.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xlogreader-reqlen.patch" diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 69b6226f8f..cbc7e4e7ea 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -536,7 +536,7 @@ ReadPageInternal(XLogReaderState *state, XLogRecPtr pageptr, int reqLen) /* check whether we have all the requested data already */ if (targetSegNo == state->readSegNo && targetPageOff == state->readOff && - reqLen < state->readLen) + reqLen <= state->readLen) return state->readLen; /* --------------1F92CF77D83EF3F8A4B8F2C7--