Skip to content

Commit 7c89a5a

Browse files
committed
Add more about LRU-2.
1 parent 0ca231f commit 7c89a5a

File tree

2 files changed

+146
-4
lines changed

2 files changed

+146
-4
lines changed

doc/TODO.detail/optimizer

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ From owner-pgsql-hackers@hub.org Thu Jan 20 18:45:32 2000
10591059
Received: from renoir.op.net (root@renoir.op.net [207.29.195.4])
10601060
by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id TAA00672
10611061
for <pgman@candle.pha.pa.us>; Thu, 20 Jan 2000 19:45:30 -0500 (EST)
1062-
Received: from hub.org (hub.org [216.126.84.1]) by renoir.op.net (o1/$Revision: 1.17 $) with ESMTP id TAA01989 for <pgman@candle.pha.pa.us>; Thu, 20 Jan 2000 19:39:15 -0500 (EST)
1062+
Received: from hub.org (hub.org [216.126.84.1]) by renoir.op.net (o1/$Revision: 1.18 $) with ESMTP id TAA01989 for <pgman@candle.pha.pa.us>; Thu, 20 Jan 2000 19:39:15 -0500 (EST)
10631063
Received: from localhost (majordom@localhost)
10641064
by hub.org (8.9.3/8.9.3) with SMTP id TAA00957;
10651065
Thu, 20 Jan 2000 19:35:19 -0500 (EST)
@@ -1919,4 +1919,3 @@ Best Regards,
19191919
Tiago
19201920
PS - again: I'm starting, so, some of my comments can be completly dumb.
19211921

1922-

doc/TODO.detail/performance

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ From owner-pgsql-hackers@hub.org Tue Oct 19 10:31:10 1999
345345
Received: from renoir.op.net (root@renoir.op.net [209.152.193.4])
346346
by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id KAA29087
347347
for <maillist@candle.pha.pa.us>; Tue, 19 Oct 1999 10:31:08 -0400 (EDT)
348-
Received: from hub.org (hub.org [216.126.84.1]) by renoir.op.net (o1/$Revision: 1.2 $) with ESMTP id KAA27535 for <maillist@candle.pha.pa.us>; Tue, 19 Oct 1999 10:19:47 -0400 (EDT)
348+
Received: from hub.org (hub.org [216.126.84.1]) by renoir.op.net (o1/$Revision: 1.3 $) with ESMTP id KAA27535 for <maillist@candle.pha.pa.us>; Tue, 19 Oct 1999 10:19:47 -0400 (EDT)
349349
Received: from localhost (majordom@localhost)
350350
by hub.org (8.9.3/8.9.3) with SMTP id KAA30328;
351351
Tue, 19 Oct 1999 10:12:10 -0400 (EDT)
@@ -454,7 +454,7 @@ From owner-pgsql-hackers@hub.org Tue Oct 19 21:25:30 1999
454454
Received: from renoir.op.net (root@renoir.op.net [209.152.193.4])
455455
by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id VAA28130
456456
for <maillist@candle.pha.pa.us>; Tue, 19 Oct 1999 21:25:26 -0400 (EDT)
457-
Received: from hub.org (hub.org [216.126.84.1]) by renoir.op.net (o1/$Revision: 1.2 $) with ESMTP id VAA10512 for <maillist@candle.pha.pa.us>; Tue, 19 Oct 1999 21:15:28 -0400 (EDT)
457+
Received: from hub.org (hub.org [216.126.84.1]) by renoir.op.net (o1/$Revision: 1.3 $) with ESMTP id VAA10512 for <maillist@candle.pha.pa.us>; Tue, 19 Oct 1999 21:15:28 -0400 (EDT)
458458
Received: from localhost (majordom@localhost)
459459
by hub.org (8.9.3/8.9.3) with SMTP id VAA50745;
460460
Tue, 19 Oct 1999 21:07:23 -0400 (EDT)
@@ -552,3 +552,146 @@ Inoue@tpf.co.jp
552552

553553
************
554554

555+
From pgsql-hackers-owner+M6267@hub.org Sun Aug 27 21:46:37 2000
556+
Received: from hub.org (root@hub.org [216.126.84.1])
557+
by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id UAA07972
558+
for <pgman@candle.pha.pa.us>; Sun, 27 Aug 2000 20:46:36 -0400 (EDT)
559+
Received: from hub.org (majordom@localhost [127.0.0.1])
560+
by hub.org (8.10.1/8.10.1) with SMTP id e7S0kaL27996;
561+
Sun, 27 Aug 2000 20:46:36 -0400 (EDT)
562+
Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2])
563+
by hub.org (8.10.1/8.10.1) with ESMTP id e7S05aL24107
564+
for <pgsql-hackers@postgreSQL.org>; Sun, 27 Aug 2000 20:05:36 -0400 (EDT)
565+
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
566+
by sss2.sss.pgh.pa.us (8.9.3/8.9.3) with ESMTP id UAA01604
567+
for <pgsql-hackers@postgreSQL.org>; Sun, 27 Aug 2000 20:05:29 -0400 (EDT)
568+
To: pgsql-hackers@postgreSQL.org
569+
Subject: [HACKERS] Possible performance improvement: buffer replacement policy
570+
Date: Sun, 27 Aug 2000 20:05:29 -0400
571+
Message-ID: <1601.967421129@sss.pgh.pa.us>
572+
From: Tom Lane <tgl@sss.pgh.pa.us>
573+
X-Mailing-List: pgsql-hackers@postgresql.org
574+
Precedence: bulk
575+
Sender: pgsql-hackers-owner@hub.org
576+
Status: ORr
577+
578+
Those of you with long memories may recall a benchmark that Edmund Mergl
579+
drew our attention to back in May '99. That test showed extremely slow
580+
performance for updating a table with many indexes (about 20). At the
581+
time, it seemed the problem was due to bad performance of btree with
582+
many equal keys, so I thought I'd go back and retry the benchmark after
583+
this latest round of btree hackery.
584+
585+
The good news is that btree itself seems to be pretty well fixed; the
586+
bad news is that the benchmark is still slow for large numbers of rows.
587+
The problem is I/O: the CPU mostly sits idle waiting for the disk.
588+
As best I can tell, the difficulty is that the working set of pages
589+
needed to update this many indexes is too large compared to the number
590+
of disk buffers Postgres is using. (I was running with -B 1000 and
591+
looking at behavior for a 100000-row test table. This gave me a table
592+
size of 3876 pages, plus 11526 pages in 20 indexes.)
593+
594+
Of course, there's only so much we can do when the number of buffers
595+
is too small, but I still started to wonder if we are using the buffers
596+
as effectively as we can. Some tracing showed that most of the pages
597+
of the indexes were being read and written multiple times within a
598+
single UPDATE query, while most of the pages of the table proper were
599+
fetched and written only once. That says we're not using the buffers
600+
as well as we could; the index pages are not being kept in memory when
601+
they should be. In a query like this, we should displace main-table
602+
pages sooner to allow keeping more index pages in cache --- but with
603+
the simple LRU replacement method we use, once a page has been loaded
604+
it will stay in cache for at least the next NBuffers (-B) page
605+
references, no matter what. With a large NBuffers that's a long time.
606+
607+
I've come across an interesting article:
608+
The LRU-K Page Replacement Algorithm For Database Disk Buffering
609+
Elizabeth J. O'Neil, Patrick E. O'Neil, Gerhard Weikum
610+
Proceedings of the 1993 ACM SIGMOD international conference
611+
on Management of Data, May 1993
612+
(If you subscribe to the ACM digital library, you can get a PDF of this
613+
from there.) This article argues that standard LRU buffer management is
614+
inherently not great for database caches, and that it's much better to
615+
replace pages on the basis of time since the K'th most recent reference,
616+
not just time since the most recent one. K=2 is enough to get most of
617+
the benefit. The big win is that you are measuring an actual page
618+
interreference time (between the last two references) and not just
619+
dealing with a lower-bound guess on the interreference time. Frequently
620+
used pages are thus much more likely to stay in cache.
621+
622+
It looks like it wouldn't take too much work to replace shared buffers
623+
on the basis of LRU-2 instead of LRU, so I'm thinking about trying it.
624+
625+
Has anyone looked into this area? Is there a better method to try?
626+
627+
regards, tom lane
628+
629+
From prlw1@newn.cam.ac.uk Fri Jan 19 12:54:45 2001
630+
Received: from henry.newn.cam.ac.uk (henry.newn.cam.ac.uk [131.111.204.130])
631+
by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id MAA29822
632+
for <pgman@candle.pha.pa.us>; Fri, 19 Jan 2001 12:54:44 -0500 (EST)
633+
Received: from [131.111.204.180] (helo=quartz.newn.cam.ac.uk)
634+
by henry.newn.cam.ac.uk with esmtp (Exim 3.13 #1)
635+
id 14JfkU-0001WA-00; Fri, 19 Jan 2001 17:54:54 +0000
636+
Received: from prlw1 by quartz.newn.cam.ac.uk with local (Exim 3.13 #1)
637+
id 14Jfj6-0001cq-00; Fri, 19 Jan 2001 17:53:28 +0000
638+
Date: Fri, 19 Jan 2001 17:53:28 +0000
639+
From: Patrick Welche <prlw1@newn.cam.ac.uk>
640+
To: Bruce Momjian <pgman@candle.pha.pa.us>
641+
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@postgreSQL.org
642+
Subject: Re: [HACKERS] Possible performance improvement: buffer replacement policy
643+
Message-ID: <20010119175328.A6223@quartz.newn.cam.ac.uk>
644+
Reply-To: prlw1@cam.ac.uk
645+
References: <1601.967421129@sss.pgh.pa.us> <200101191703.MAA25873@candle.pha.pa.us>
646+
Mime-Version: 1.0
647+
Content-Type: text/plain; charset=us-ascii
648+
Content-Disposition: inline
649+
User-Agent: Mutt/1.2i
650+
In-Reply-To: <200101191703.MAA25873@candle.pha.pa.us>; from pgman@candle.pha.pa.us on Fri, Jan 19, 2001 at 12:03:58PM -0500
651+
Status: OR
652+
653+
On Fri, Jan 19, 2001 at 12:03:58PM -0500, Bruce Momjian wrote:
654+
>
655+
> Tom, did we ever test this? I think we did and found that it was the
656+
> same or worse, right?
657+
658+
(Funnily enough, I just read that message:)
659+
660+
To: Bruce Momjian <pgman@candle.pha.pa.us>
661+
cc: pgsql-hackers@postgreSQL.org
662+
Subject: Re: [HACKERS] Possible performance improvement: buffer replacement policy
663+
In-reply-to: <200010161541.LAA06653@candle.pha.pa.us>
664+
References: <200010161541.LAA06653@candle.pha.pa.us>
665+
Comments: In-reply-to Bruce Momjian <pgman@candle.pha.pa.us>
666+
message dated "Mon, 16 Oct 2000 11:41:41 -0400"
667+
Date: Mon, 16 Oct 2000 11:49:52 -0400
668+
Message-ID: <26100.971711392@sss.pgh.pa.us>
669+
From: Tom Lane <tgl@sss.pgh.pa.us>
670+
X-Mailing-List: pgsql-hackers@postgresql.org
671+
Precedence: bulk
672+
Sender: pgsql-hackers-owner@hub.org
673+
Status: RO
674+
Content-Length: 947
675+
Lines: 19
676+
677+
Bruce Momjian <pgman@candle.pha.pa.us> writes:
678+
>> It looks like it wouldn't take too much work to replace shared buffers
679+
>> on the basis of LRU-2 instead of LRU, so I'm thinking about trying it.
680+
>>
681+
>> Has anyone looked into this area? Is there a better method to try?
682+
683+
> Sounds like a perfect idea. Good luck. :-)
684+
685+
Actually, the idea went down in flames :-(, but I neglected to report
686+
back to pghackers about it. I did do some code to manage buffers as
687+
LRU-2. I didn't have any good performance test cases to try it with,
688+
but Richard Brosnahan was kind enough to re-run the TPC tests previously
689+
published by Great Bridge with that code in place. Wasn't any faster,
690+
in fact possibly a little slower, likely due to the extra CPU time spent
691+
on buffer freelist management. It's possible that other scenarios might
692+
show a better result, but right now I feel pretty discouraged about the
693+
LRU-2 idea and am not pursuing it.
694+
695+
regards, tom lane
696+
697+

0 commit comments

Comments
 (0)