Re: WIP: WAL prefetch (another approach)
Tomas Vondra <tomas.vondra@enterprisedb.com>
Attachments
- wal-prefetching.png (image/png)
Hi, I did a bunch of tests on v15, mostly to asses how much could the prefetching help. The most interesting test I did was this: 1) primary instance on a box with 16/32 cores, 64GB RAM, NVMe SSD 2) replica on small box with 4 cores, 8GB RAM, SSD RAID 3) pause replication on the replica (pg_wal_replay_pause) 4) initialize pgbench scale 2000 (fits into RAM on primary, while on replica it's about 4x RAM) 5) run 1h pgbench: pgbench -N -c 16 -j 4 -T 3600 test 6) resume replication (pg_wal_replay_resume) 7) measure how long it takes to catch up, monitor lag This is nicely reproducible test case, it eliminates influence of network speed and so on. Attached is a chart showing the lag with and without the prefetching. In both cases we start with ~140GB of redo lag, and the chart shows how quickly the replica applies that. The "waves" are checkpoints, where right after a checkpoint the redo gets much faster thanks to FPIs and then slows down as it gets to parts without them (having to do synchronous random reads). With master, it'd take ~16000 seconds to catch up. I don't have the exact number, because I got tired of waiting, but the estimate is likely accurate (judging by other tests and how regular the progress is). With WAL prefetching enabled (I bumped up the buffer to 2MB, and prefetch limit to 500, but that was mostly just arbitrary choice), it finishes in ~3200 seconds. This includes replication of the pgbench initialization, which took ~200 seconds and where prefetching is mostly useless. That's a damn pretty improvement, I guess! In a way, this means the tiny replica would be able to keep up with a much larger machine, where everything is in memory. One comment about the patch - the postgresql.conf.sample change says: #recovery_prefetch = on # whether to prefetch pages logged with FPW #recovery_prefetch_fpw = off # whether to prefetch pages logged with FPW but clearly that comment is only for recovery_prefetch_fpw, the first GUC enables prefetching in general. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix recovery_prefetch docs.
- dafae9707ab7 15.0 landed
-
Prefetch data referenced by the WAL, take II.
- 5dc0418fab28 15.0 landed
-
Add circular WAL decoding buffer, take II.
- 3f1ce973467a 15.0 landed
-
Fix generation of ./INSTALL for the distribution tarball
- 45aa88fe1d40 14.0 cited
-
Revert recovery prefetching feature.
- c2dc19342e05 14.0 landed
-
Sync guc.c and postgresql.conf.sample with the SGML docs.
- a55a98477b69 14.0 cited
-
Add information of total data processed to replication slot stats.
- f5fc2f5b23d1 14.0 cited
-
Doc: Review for "Optionally prefetch referenced data in recovery."
- dc88460c24ed 14.0 landed
-
Add circular WAL decoding buffer.
- f003d9f8721b 14.0 landed
-
Optionally prefetch referenced data in recovery.
- 1d257577e08d 14.0 landed
-
Remove read_page callback from XLogReader.
- 323cbe7c7ddc 14.0 cited
-
Provide ReadRecentBuffer() to re-pin buffers by ID.
- 2f27f8c51149 14.0 landed
-
Provide recovery_init_sync_method=syncfs.
- 61752afb2640 14.0 cited
-
Mark factorial operator, and postfix operators in general, as deprecated.
- 6ca547cf75ef 14.0 cited
-
Rationalize GetWalRcv{Write,Flush}RecPtr().
- d140f2f3e225 13.0 landed
-
Support PrefetchBuffer() in recovery.
- 3985b600f57d 13.0 landed
-
Prevent hard failures of standbys caused by recycled WAL segments
- 70b4f82a4b5c 11.0 cited