Re: bgwriter changes - Mailing list pgsql-hackers

From Simon Riggs
Subject Re: bgwriter changes
Date
Msg-id 1103103505.4037.3860.camel@localhost.localdomain
Whole thread Raw
In response to bgwriter changes  (Neil Conway <neilc@samurai.com>)
Responses Re: bgwriter changes
List pgsql-hackers
On Tue, 2004-12-14 at 13:30, Neil Conway wrote:
> In recent discussion[1] with Simon Riggs, there has been some talk of 
> making some changes to the bgwriter. To summarize the problem, the 
> bgwriter currently scans the entire T1+T2 buffer lists and returns a 
> list of all the currently dirty buffers. It then selects a subset of 
> that list (computed using bgwriter_percent and bgwriter_maxpages) to 
> flush to disk. Not only does this mean we can end up scanning a 
> significant portion of shared_buffers for every invocation of the 
> bgwriter, we also do the scan while holding the BufMgrLock, likely 
> hurting scalability.

Neil's summary is very clear, many thanks.

There has been many suggestions, patches and test results, so I have
attempted to summarise everything here, using Neil's post to give
structure to the other information:

> I think a fix for this in some fashion is warranted for 8.0. Possible 
> solutions:

I add 2 things to this structure
i) the name of the patch that implements that (authors initials)
ii) benchmark results published that run those

> (1) Special-case bgwriter_percent=100. The only reason we need to return 
> a list of all the dirty buffers is so that we can choose n% of them to 
> satisfy bgwriter_percent. That is obviously unnecessary if we have 
> bgwriter_percent=100. I think this change won't help most users, 
> *unless* we also change bgwriter_percent=100 in the default configuration.

100pct.patch (SR)

Test results to date:
1. Mark Kirkwood ([HACKERS] [Testperf-general] BufferSync and bgwriter)
pgbench 1xCPU 1xDisk shared_buffers=10000
showed 8.0RC1 had regressed compared with 7.4.6, but patch improved
performance significantly against 8.0RC1

Discounted now by both Neil and myself, since the same idea has been
more generally implemented as ideas (2) and (3) below.

> (2) Remove bgwriter_percent. I have yet to hear anyone argue that 
> there's an actual need for bgwriter_percent in tuning bgwriter behavior, 
> and one less GUC var is a good thing, all else being equal. This is 
> effectively the same as #1 with the default changed, only less flexibility.

There are 2 patches published which do same thing:
- Partially implemented following Neil's suggestion: bg3.patch (SR)
- Fully implemented: bgwriter_rem_percent-1.patch (NC)
Patches have an identical effect on performance.

Test results to date:
1. Neil's testing was "inconclusive" for shared_buffers = 2500 on a
single cpu, single disk system (test used bgwriter_rem_percent-1.patch)
2. Mark Wong's OSDL tests published as test 211
analysis already posted on this thread; 
dbt-2 4 CPU, many disk, shared_buffers=60000 (test used bg3.patch)
3% overall benefit, greatly reduced max transaction times
3. Mark Kirkwood's tests
pgbench 2xCPU 2xdisk, shared_buffers=10000 (test used
bgwriter_rem_percent-1.patch)
Showed slight regression against RC1 - must be test variability because
the patch does less work and is very unlikely to cause a regression

> (3) Change the meaning of bgwriter_percent, per Simon's proposal. Make 
> it mean "the percentage of the buffer pool to scan, at most, to look for 
> dirty buffers". I don't think this is workable, at least not at this 
> point in the release cycle, because it means we might not smooth of 
> checkpoint load, one of the primary goals of the bgwriter (in this 
> proposal bgwriter would only ever consider writing out a small subset of 
> the total shared buffer cache: the least-recently-used n%, with 2% being 
> a suggested default). Some variant of this might be worth exploring for 
> 8.1 though.

Implemented as bg2.patch (SR)
Contains a small bug, easily fixed, which would not effect performance

Test results to date:
1. Mark Kirkwood's tests
pgbench 2xCPU 2xdisk, shared_buffers=10000 (test used bg2.patch)
Showed improvement on RC1 and best option out of all three tests
(compared RC1, bg2.patch, bgwriter_rem_percent-1.patch), possibly
similar within bounds of test variability - but interesting enough to
investigate further.

Current situation seems to be:
- all test results indicate performance regressions in RC1 when
shared_buffers >= 10000 and using multi-cpu/multi-disk systems
- option (2) has the most thoroughly confirmable test results and is
thought by all parties to be the simplest and most robust approach.
- some more test results would be useful to compare, to ensure that
applying the patch would be useful in all circumstances.

Approach (3) looks interesting and should be investigated for 8.1, since
it introduces a subtlely different algorithm that may have "interesting
flight characteristics" and is more of a risk to the 8.0 release.

Thanks very much to all performance testers. It's important work.

-- 
Best Regards, Simon Riggs



pgsql-hackers by date:

Previous
From: Joe Conway
Date:
Subject: Re: production server down
Next
From: "Zeugswetter Andreas DAZ SD"
Date:
Subject: Re: bgwriter changes