| From: | Tomas Vondra <tomas(at)vondra(dot)me> |
|---|---|
| To: | Ken Marshall <ktm(at)rice(dot)edu>, Hannu Krosing <hannuk(at)google(dot)com> |
| Cc: | Andreas Karlsson <andreas(at)proxel(dot)se>, Christoph Berg <myon(at)debian(dot)org>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, wenhui qiu <qiuwenhuifx(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Andres Freund <andres(at)anarazel(dot)de>, Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Japin Li <japinli(at)hotmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, John Naylor <johncnaylorls(at)gmail(dot)com> |
| Subject: | Re: WAL compression setting after PostgreSQL LZ4 default change |
| Date: | 2026-08-07 08:23:15 |
| Message-ID: | 1a39cbd6-6528-4f04-8d19-54e3790f006a@vondra.me |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 8/6/26 17:32, Tomas Vondra wrote:
>
>
> On 8/6/26 16:50, Ken Marshall wrote:
>> On Thu, Aug 06, 2026 at 04:31:44PM +0200, Hannu Krosing wrote:
>>> On Thu, Aug 6, 2026 at 2:11 PM Tomas Vondra <tomas(at)vondra(dot)me> wrote:
>>>>
>>>> The executive summary is that lz4/zstd perform about the same, but zstd
>>>> has a clearly better compression ratio. I withdraw my initial plan to
>>>> default to lz4, and I agree we should default to zstd. (By "default" I
>>>> mean that "on" would use that algorithm, but the GUC would still default
>>>> to 'off' as before. Maybe we should reconsinder that for PG20, though?)
>>>
>>> Do you have any ideas why recovery on Azure is 10-20% faster for lz4
>>> (and surprisingly also pglz) than for zstd ?
>>>
>
> I don't, but I'll do a couple more runs with for these parameters
> (zstd/3, lz4/1 and pglz), to see how stable the results are.
>
> Might be interesting to run this on other cloud instances, but I don't
> have access to those at the moment.
>
> Could this be due to difference in decompression speed? I've seen
> figures like 2GB/s for zstd vs. 4GB/s for lz4. We're we'd dealing with
> ~45GB of WAL, so that'd be 25 vs. 10 seconds, which is not far from the
> ~20s difference in recovery time. Then again, it only affects azure, so
> there's some hw influence.
>
I've done more testing on the azure instances. The timings are very
consistent - with lz4 it takes 156s +/- 2s, with zstd it's 172s +/- 2s
(so ~10% difference). After some profiling, I think it really is due to
the lower zstd decompression speed. The CPU profiles look like this:
18.64% postgres postgres [.] pg_checksum_block_avx2
11.13% postgres postgres [.] hash_search_with_hash_value
10.08% postgres liblz4.so.1.10.0 [.] LZ4_decompress_safe
3.56% postgres postgres [.] FlushBuffer.constprop.0
2.65% postgres libc.so.6 [.] __internal_syscall_cancel
2.33% postgres libc.so.6 [.] __memmove_avx512_...
2.04% postgres postgres [.] LWLockAttemptLock
vs.
12.41% postgres libzstd.so.1.5.7 [.] ZSTD_decompressSequences...
12.24% postgres postgres [.] pg_checksum_block_avx2
8.25% postgres libzstd.so.1.5.7 [.] ZSTD_createDCtx_internal
6.76% postgres postgres [.] hash_search_with_hash_value
4.35% postgres libzstd.so.1.5.7 [.] ZSTD_buildFSETable_...
4.17% postgres libzstd.so.1.5.7 [.] HUF_readDTableX1_wksp...
2.34% postgres postgres [.] FlushBuffer.constprop.0
2.23% postgres libzstd.so.1.5.7 [.] HUF_readStats_body_bmi2...
2.19% postgres libzstd.so.1.5.7 [.] FSE_decompress_wksp_body_...
1.73% postgres libc.so.6 [.] __internal_syscall_cancel
1.56% postgres libc.so.6 [.] __memmove_avx512_...
1.32% postgres postgres [.] LWLockAttemptLock
The ZSTD decompression takes much bigger fraction of the CPU time, so
that would explain this.
Why it happens only on the azure instances is fairly simple - those
instances have better local NVMe storage, so the bottleneck is CPU. On
the other machines (ryzen/xeon), the local storage is slower, which
helps the higher compression ratio with zstd.
I suspect using network storage would benefit from that too ...
regards
--
Tomas Vondra
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrey Borodin | 2026-08-07 08:34:23 | Re: WAL compression setting after PostgreSQL LZ4 default change |
| Previous Message | Bertrand Drouvot | 2026-08-07 08:18:18 | Re: Re-read subscription state after lock in AlterSubscription |