| From: | Xuneng Zhou <xunengzhou(at)gmail(dot)com> |
|---|---|
| To: | Imran Zaheer <imran(dot)zhir(at)gmail(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: [WIP] Pipelined Recovery |
| Date: | 2026-12-02 06:28:21 |
| Message-ID: | CABPTF7V0t1vHYpu+Y6YeqKg8ryLoRo0HENWyz_h93CAF+9dtQg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Imran,
Here are some thoughts for the patch after review, as promised. I see the
benchmark results posted earlier are promising, but the picture is less
clear once we zoom out a bit.
To see why, we may need to revisit the idea's origin. Ants proposed it in
[1]: split WAL decoding, buffer lookup and maybe pinning off into a helper
process. Andres and Thomas [2] [3] viewed this as a possible direction but
thought there're plenty of opportunities to gain in one process before
considering another, e.g., better buffer lookup and streamifying recovery.
So I profiled the startup process on master (tpcb-like, in memory). Very
roughly, redo are 46% of its CPU, the prefetcher 23%, and reading plus
decoding WAL 16%. Across the first two, buffer mapping lookups are about
11% and smgropen() about 5%, so the lookups cost as much as decoding.
That impliess something about the v6. Its helper decodes and runs the
prefetcher. Decoding alone cannot explain the gain, a fair amount comes
from offloading the prefetcher's lookups from the startup to helper process.
To check, I built a prototype on v6. In which the startup keeps all
decisions about where WAL comes from as suggested earlier.
v6+at v6 plus Jakub's atomics patch
D the helper only decodes; the startup process prefetches
v6+at D
crash recovery, tpcb-like 1.32x 1.07x
crash recovery, simple-update 1.29x 1.06x
standby, 7.9GB backlog 1.06x 1.03x
crash recovery, I/O-bound 0.36x 1.00x
D confirms the guess: decoding alone brings a few percent. Some extra gains
are lost over the copy handover of decoded record from helper process to
the startup. We could improve that slightly by letting the helper write the
records into shared memory for in-place use by the startup process, but
this still only got 1.12x in my experiment, at the cost of inventing a new
facility.
This may matter less if the patch can keep v6 shape, where the prefecher
gain stays. However, something emerging works could change that -- Thomas
said recently that he plans to post some patches of aio recovery[4]. From
the preview[5], the prefetcher becomes a read stream that find, reads and
pins page ahead of replay, all in the startup, and redo receives already
pinned buffer. That conflicts with v6. Its helper process runs the
prefetcher, which is the code the stream replaces, and a stream cannot move
to the helper because pins belong to the process that took them.
Would the stream also take away the helper gains? Partly, I guess. Today,
the startup handles each block twice: the prefetcher looks it up, and redo
checks and pins it again. The stream handles this once, saving the second
step, about 5% in my profile. The lookup itself stays in the startup, so a
helper could still take it. However, the potential gain could shrink
further. Thomas described ideas in [3] for skipping the mapping lookup in
the stream, by reusing pins it already holds or by remembering recent
buffers per relation. It would leave less for a helper.
So the question becomes: if many gains are reachable within one process, is
it worthwhile to introduce a separate one for now? If so, how to march them
forward together?
Additionally, my benchmark runs exposed two problems in v6:
standby, 7.9GB backlog 1.06x
crash recovery, I/O-bound 0.36x
On the backlog, the helper's prefetcher treats almost every block as new
(skip_new 90M, hit 0), so no buffer hint reaches redo and the startup does
all the lookups itself. In the I/O-bound test, the helper issues read-ahead
far ahead of replay, and the pages are evicted again before replay reaches
them (269s against 97s on master).
Anyway, they feel less important than the first question for now.
[1]
https://postgr.es/m/CANwKhkO0WJpp147eSmdiHU9KobqhkHzMi0+DR-TWz8FM7jMHVw@mail.gmail.com
[2]
https://postgr.es/m/ii7jyq47owdsce5bwelxusaknc7fqsnhuljnx4vfafu5ob7sy6@akljdxwtnhiw
[3]
https://postgr.es/m/CA+hUKG+K_0-gYFiEZXNSz0=rv5YwN5LdVmZHVdLUO3DoKypc7w@mail.gmail.com
[4]
https://postgr.es/m/CA+hUKGJpKFpAB-du_m3zzZmRjdg_V65TsLj_DDMSJnzikWDG7w@mail.gmail.com
[5]
https://github.com/macdice/postgres/commit/52533b652e544464add6f174019161889a37ed93
--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Julien Rouhaud | 2026-12-02 06:41:51 | Missing CFI() in SplitIdentifierString |
| Previous Message | Hüseyin Demir | 2026-12-02 06:25:12 | Re: [PATCH] Report changes discarded for relations not in the subscription |