Discussion:
Incremental checkopints
j***@go-link.net
2011-07-29 15:04:52 UTC
Permalink
Hi,
I have read all information about checkpoints in PostgreSQL I have found.
I think that current implementation of checkpoints is not good for huge
shared buffer cache and for many WAL segments. If there is more buffers
and if buffers can be written rarely more updates of buffers can be
combined so total number of writes to disk will be significantly less. I
think that incremental checkpoints can achieve this goal (maybe more) and
price is additional memory (about 1/1000 of size of buffer cache).

My main source of information is
http://wiki.postgresql.org/wiki/User:Gsmith#How_do_checkpoints_happen_inside_the_PostgreSQL_backend.3F
I see that some data are required to be written into WAL in 3) and 6). I
will use CD to denote that data and P1, P2... to denote pages that are
dirty and has to be written to disk in 4).

In incremental checkpoint when WAL segment has written we will not start
writing but we will add to queue pages P1, P2 ... and CD. If meanwhile
background writer has to clean some page that page is removed from queue.
When checkpoint_segments are written in the transaction log we have in
queue:
P1, P2 ... CD, Pi ... CD, Pj ... CD ...
Here we have to make checkpoint in order to free first WAL segment. Only
pages before first CD have to be written and fsync’d.

I suppose that this task can be done in background writer. So first we can
make some number of writes per round both lru and checkpoint. There is no
deadline for each incremental checkpoint but if WAL is growing total
number of writes have to increase. Also it is not required to do
checkpoint for each WAL segment. It is possible to write N pages from
queue and to combine several potential checkpoint in one.

I hope I have explained the general idea. I am not C programmer so it is
hard to me to give more details.

Jordan Ivanov
--
Sent via pgsql-hackers mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Greg Smith
2011-07-29 19:03:06 UTC
Permalink
Post by j***@go-link.net
I think that current implementation of checkpoints is not good for huge
shared buffer cache and for many WAL segments. If there is more buffers
and if buffers can be written rarely more updates of buffers can be
combined so total number of writes to disk will be significantly less. I
think that incremental checkpoints can achieve this goal (maybe more) and
price is additional memory (about 1/1000 of size of buffer cache).
The current code optimizes for buffers that are written frequently.
Those will sit in shared_buffers and in the hoped for case, only be
written once at checkpoint time.

There are two issues with adopting increment checkpoints instead, one
fundamental, the other solvable but not started on yet:

1) Postponing writes as long as possible always improves the resulting
throughput of those writes. Any incremental checkpoint approach will
detune throughput by some amount. If you make writes go out more often,
they will be less efficient; that's just how things work if you
benchmark anything that allows write combining. Any incremental
checkpoint approach is likely to improve latency in some cases if it
works well, while decreasing throughput in most cases.

2) The incremental checkpoint approach used by other databases, such as
the MySQL implementation, works by tracking what transaction IDs were
associated with a buffer update. The current way PostgreSQL saves
buffer sync information for the checkpoint to process things doesn't
store enough information to do that. As you say, the main price there
is some additional memory.

From my perspective, the main problem with plans to tweak the
checkpoint code is that we don't have a really good benchmark that
tracks both throughput and latency to test proposed changes against.
Mark Wong has been working to get his TCP-E clone DBT-5 running
regularly for that purpose, and last I heard that was basically done at
this point--he's running daily tests now. There's already a small pile
of patches that adjust checkpoint behavior around that were postponed
from being included in 9.1 mainly because it was hard to prove they were
useful given the benchmark used to test them, pgbench. I have higher
hopes for DBT-5 as being a test that gives informative data in this
area. I would want to go back and revisit the existing patches (sorted
checkpoints, spread sync) before launching into this whole new area. I
don't think any of those has even been proven not to work, they just
didn't help the slightly unrealistic pgbench write-heavy workload.
--
Greg Smith 2ndQuadrant US ***@2ndQuadrant.com Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us
--
Sent via pgsql-hackers mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Robert Haas
2011-08-03 16:10:32 UTC
Permalink
This post might be inappropriate. Click to display it.
j***@go-link.net
2011-07-30 05:23:44 UTC
Permalink
If you make writes go out more often, they will be less efficient
I think fsync is more important. But many writes + fsync is no good too.
Let suppose that 30 WAL segments are good for performance (to be written
at once). In incremental approach we can have 60 segments and we can write
30 at once. There is no checkpoint_timeout - more buffers will stay more
time.

I can not see any disadvantage.

Jordan Ivanov
--
Sent via pgsql-hackers mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
j***@go-link.net
2011-08-04 02:24:05 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...