pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Arthur Zakirov <a.zakirov@postgrespro.ru>
To: pgsql-hackers@lists.postgresql.org
Cc: Grigory Smolkin <g.smolkin@postgrespro.ru>
Subject: [PATCH] xlogreader: do not read a file block twice
Date: Mon, 11 Feb 2019 19:25:39 +0300
Message-ID: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru> (raw)

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

Attachments:

  [text/x-patch] xlogreader-reqlen.patch (544B, ../2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru/2-xlogreader-reqlen.patch)
  download | inline diff:
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;
 
 	/*

view thread (11+ messages)  latest in thread

Message-ID: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru>
Permalink:  ../2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru/
Also on:    postgresql.org/message-id/2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: a.zakirov@postgrespro.ru, pgsql-hackers@lists.postgresql.org, g.smolkin@postgrespro.ru
  Subject: Re: [PATCH] xlogreader: do not read a file block twice
  In-Reply-To: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox