Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8SeB-0010n1-BD for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 00:12:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v8Se8-009FQO-T9 for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 00:12:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8Se8-009FQ9-IA for pgsql-hackers@lists.postgresql.org; Tue, 14 Oct 2025 00:12:09 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v8ScI-0021JP-22 for pgsql-hackers@lists.postgresql.org; Tue, 14 Oct 2025 00:12:09 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-b556284db11so4198482a12.0 for ; Mon, 13 Oct 2025 17:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760400612; x=1761005412; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=W53KlRSCwg01RRdrIrfu9d5UFLu3JxJkS/eLPQCM+QQ=; b=Vgvsuz+kEEBnXSpEVQsjM7DcQOp5iFpHieUdjyyC8rHQaUphhPMtTUKrru0BeolnkQ hVXI/1OO0m0ZVKRXKJCnVohwbdjERgx28eQ26yfHyFohlM76MvdATroWjiqipTZWaJRe 7h3WYZIooFN9na4OwKUcmGVMwTaMBaSZMumHvtuxK7SCnu2JBFPlnqFAALC7Yfn2sC1v iGajbMhEFFEyMezM9mFIIbsko0BRyEQMyUE9WtGPr9y5fB7xIMPR9RRmXKVUfn26bTqA ZGkRdEXF7xs6d4K0LU05o90m+WsVficunoJyuEfDhu2Y9AyDw4pXIVzGcfSKbdDQaQuu QXCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760400612; x=1761005412; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W53KlRSCwg01RRdrIrfu9d5UFLu3JxJkS/eLPQCM+QQ=; b=osikZnDlZGoAc3lW1iSBrBuqxHgKo5fKxpqMdl2L6q9SenN3ZWdI/2xiZvxmCU5xZw LBoYS1ZagVzOIswcM/H925a3Nq7w3DjX+BP6eeSs1xdmbF+IvFmnC3Atg8RYfP13j0aQ lDDWFPn56I0gMgx1YTo92et1kiyt2Xi7tag+q2HxFgKK1VOb1aiOyV7fyZayhqYUcriF iRr+LGWc/SjNt/SXiDezY6HIwlyEH5b6w57Sc5hAjSMBn0mtApf93plhXKnbqHATHbAJ UvGhOBcaS/mLlGwfPf7epx6d91SFCxW8Js72/xom9D6XHYUx5HwmuDlOE3XYbp7xmzfR q84Q== X-Forwarded-Encrypted: i=1; AJvYcCU5BQjFm/yFn/fqr8S4GhYhEP2HxIeepYLL2F67BD63LWOWAAQwUou/4104gUvlxYh0RgrOZd6Ku5GBue5j@lists.postgresql.org X-Gm-Message-State: AOJu0Yzw4lfo1MxdLn8bhBH9TivmOdF/+dtIEmvJV8HA9kqWbls8QyRK l7yMw8i6BtvQD93BJUP9zBkbldSVfCanF6vd/4WgZLqUzpAuY25fALk4 X-Gm-Gg: ASbGncta9Iyw+NnkOU1g6C6z83YkuUKsDgSDfo3mGe5yvGA3jGRa63o8vrTtcZ1dwwl eoyHVUv1/iL5Y46cGTe1qzyu+15bBkbRIKMS5Y4s9J414EevV+39pehTPhVi0NwmE7DQKwGlbUW qNaYmqfVoMTw3MFQElJtZ30ZLM3WQepvwIwGzBCmwbyDo2z53o/wlAY3ayqagFXXr7YbFDMsRv6 aIq3zcQh2KazzHu2jX98ghk2zH+K2upppRQ9tpw5PVx8HsolFwuWG7F4LBVGh/i1DmbKi1KPn9f us3R1WphV6W5TYmCG64uzKicgATbm55hK7lKfpFgzCnCYCmLzR+3f1axQ39T//NikppN2Kiyho4 NI/MGlnFNb2k7AgCX6V4Dz3D/BEgFphQz1xvwhcic6NA7yExtcb0x X-Google-Smtp-Source: AGHT+IFugOfWsuioWGOeBUva34sOsroN2KuVU8TVmcrVruYTBDHzS2N3VHVQPm6CA5HFe4QWJdoUUw== X-Received: by 2002:a17:903:1448:b0:24b:24dc:91a7 with SMTP id d9443c01a7336-29027402b4bmr311670015ad.45.1760400611842; Mon, 13 Oct 2025 17:10:11 -0700 (PDT) Received: from smtpclient.apple ([170.178.170.211]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29076d7af28sm10539345ad.118.2025.10.13.17.10.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2025 17:10:11 -0700 (PDT) From: Chao Li Message-Id: <25A25667-AC82-46FD-A5FC-0B2AA0CC7DB9@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_4B380B2A-09F4-47E9-87BF-27A9F640DD9F" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PING] [PATCH v2] parallel pg_restore: avoid disk seeks when jumping short distance forward Date: Tue, 14 Oct 2025 08:09:56 +0800 In-Reply-To: <717335.1760389672@sss.pgh.pa.us> Cc: Dimitrios Apostolou , Nathan Bossart , Thomas Munro , pgsql-hackers@lists.postgresql.org To: Tom Lane References: <2edb7a57-b225-3b23-a680-62ba90658fec@gmx.net> <1282067.1744651649@sss.pgh.pa.us> <5ed51587-5a24-4d79-e36e-927620d0e3a2@gmx.net> <72d2c81b-a0fe-3d99-9dd4-0d771e6e673e@gmx.net> <1po8os49-r63o-2923-p37n-12698o1qn7p0@tzk.arg> <3515357.1760128017@sss.pgh.pa.us> <3698234.1760149336@sss.pgh.pa.us> <3686.1760232320@sss.pgh.pa.us> <717335.1760389672@sss.pgh.pa.us> X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_4B380B2A-09F4-47E9-87BF-27A9F640DD9F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 14, 2025, at 05:07, Tom Lane wrote: >=20 >=20 > I've pushed the parts of that patch set that I thought were > uncontroversial. What's left is the business about increasing > DEFAULT_IO_BUFFER_SIZE and then adjusting the tests appropriately. >=20 > So, v4-0001 attached is the previous v3-0002 to increase > DEFAULT_IO_BUFFER_SIZE, plus additions in compress_none.c to make > --compress=3Dnone also produce predictably large data blocks. > I decided that if we're going to rely on that behavior as part > of the solution for this thread's original problem, we'd better > make it happen for all compression options. >=20 > 0002 adds a test case in 002_pg_dump.pl to exercise --compress=3Dnone, > because without that we don't have any coverage of the new code > 0001 added in compress_none.c. That makes for a small increase > in the runtime of 002_pg_dump.pl, but I'm inclined to think it's > worth doing. >=20 > 0003 modifies the existing test cases that manually compress > blobs.toc files so that they also compress toc.dat. I feel > like it's mostly an oversight that that wasn't done to begin > with; if it had been done, we'd have caught the Gzip_read bug > right away. Also, AFAICT, this doesn't cost anything measurable > in test runtime. >=20 > 0004 increases the row width in the existing test case that says > it's trying to push more than DEFAULT_IO_BUFFER_SIZE through > the compressors. While I agree with the premise, this solution > is hugely expensive: it adds about 12% to the already-long runtime > of 002_pg_dump.pl. I'd like to find a better way, but ran out of > energy for today. (I think the reason this costs so much is that > it's effectively iterated hundreds of times because of > 002_pg_dump.pl's more or less cross-product approach to testing > everything. Maybe we should pull it out of that structure?) >=20 In v4 patch, the code changes are straightforward. 0001 changes = compress_none.c to write data to a 128K buffer first, then only flush = the buffer when it=E2=80=99s filled up. 0002, 0003 and 0004 add more = test cases. I have no comment to the code diff. I tested DEFAULT_IO_BUFFER_SIZE with 4K, 32K, 64K, 128K and 256K. Looks = like increasing the buffer size doesn=E2=80=99t improve the performance = significantly. Actually, with the buffer size 64K, 128K and 256K, the = test results are very close. I tested both with lz4 and none = compression. I am not suggesting tuning the buffer size. These data are = only for your reference. To do the test, I created a test db and filled in several GB of data. ``` 256K =3D=3D=3D=3D % time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest 3.37s user 0.82s = system 57% cpu 7.249 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.24s user 0.19s system 43% cpu = 0.991 total % time pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest 2.34s user 1.72s = system 68% cpu 5.949 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.02s user 0.19s system 22% cpu = 0.921 total 128K =3D=3D=3D % time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest 3.38s user 0.85s = system 64% cpu 6.525 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.28s user 0.21s system 47% cpu = 1.042 total % time pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest 2.34s user 1.67s = system 68% cpu 5.835 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.03s user 0.22s system 22% cpu = 1.118 total 64K =3D=3D=3D % time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest 3.39s user 0.92s = system 63% cpu 6.761 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.33s user 0.24s system 40% cpu = 1.420 total % time pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest 2.35s user 1.74s = system 69% cpu 5.849 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.04s user 0.22s system 27% cpu = 0.939 total 32K =3D=3D=3D % time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest 3.43s user 0.94s = system 58% cpu 7.416 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.34s user 0.22s system 56% cpu = 0.983 total % time pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest 2.34s user 1.75s = system 67% cpu 6.070 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.05s user 0.23s system 29% cpu = 0.926 total 4k=3D=3D=3D=3D % time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest 3.45s user 0.94s = system 60% cpu 7.298 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.37s user 0.29s system 64% cpu = 1.016 total % time pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest pg_dump -Fd --compress=3Dnone -f dump_A.dir evantest 2.33s user 1.78s = system 69% cpu 5.947 total % time pg_restore -f /dev/null dump_A.dir pg_restore -f /dev/null dump_A.dir 0.12s user 0.29s system 40% cpu = 1.009 total ``` Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_4B380B2A-09F4-47E9-87BF-27A9F640DD9F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Oct 14, 2025, at 05:07, Tom Lane = <tgl@sss.pgh.pa.us> wrote:


I've pushed the parts = of that patch set that I thought were
uncontroversial.  What's = left is the business about increasing
DEFAULT_IO_BUFFER_SIZE and then = adjusting the tests appropriately.

So, v4-0001 attached is the = previous v3-0002 to increase
DEFAULT_IO_BUFFER_SIZE, plus additions = in compress_none.c to make
--compress=3Dnone also produce predictably = large data blocks.
I decided that if we're going to rely on that = behavior as part
of the solution for this thread's original problem, = we'd better
make it happen for all compression options.

0002 = adds a test case in 002_pg_dump.pl to exercise = --compress=3Dnone,
because without that we don't have any coverage of = the new code
0001 added in compress_none.c.  That makes for a = small increase
in the runtime of 002_pg_dump.pl, but I'm inclined to = think it's
worth doing.

0003 modifies the existing test cases = that manually compress
blobs.toc files so that they also compress = toc.dat.  I feel
like it's mostly an oversight that that wasn't = done to begin
with; if it had been done, we'd have caught the = Gzip_read bug
right away.  Also, AFAICT, this doesn't cost = anything measurable
in test runtime.

0004 increases the row = width in the existing test case that says
it's trying to push more = than DEFAULT_IO_BUFFER_SIZE through
the compressors.  While I = agree with the premise, this solution
is hugely expensive: it adds = about 12% to the already-long runtime
of 002_pg_dump.pl.  I'd = like to find a better way, but ran out of
energy for today.  (I = think the reason this costs so much is that
it's effectively iterated = hundreds of times because of
002_pg_dump.pl's more or less = cross-product approach to testing
everything.  Maybe we should = pull it out of that = structure?)


In v4 patch, the = code changes are straightforward. 0001 changes compress_none.c to write = data to a 128K buffer first, then only flush the buffer when it=E2=80=99s = filled up. 0002, 0003 and 0004 add more test cases. I have no comment to = the code diff.

I tested DEFAULT_IO_BUFFER_SIZE = with 4K, 32K, 64K, 128K and 256K. Looks like increasing the buffer size = doesn=E2=80=99t improve the performance significantly. Actually, with = the buffer size 64K, 128K and 256K, the test results are very close. I = tested both with lz4 and none compression. I am not suggesting tuning = the buffer size. These data are only for your = reference.

To do the test, I created a test db = and filled in several GB of = data.

```
256K =3D=3D=3D=3D
<= div>% time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir = evantest
pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest =  3.37s user 0.82s system 57% cpu 7.249 total
% time = pg_restore -f /dev/null dump_A.dir
pg_restore -f /dev/null = dump_A.dir  0.24s user 0.19s system 43% cpu 0.991 = total

% time pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest
pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest  2.34s user 1.72s system 68% cpu 5.949 = total
% time pg_restore -f /dev/null = dump_A.dir
pg_restore -f /dev/null dump_A.dir  0.02s user = 0.19s system 22% cpu 0.921 total

128K = =3D=3D=3D
% time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir = evantest
pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest =  3.38s user 0.85s system 64% cpu 6.525 total
% time = pg_restore -f /dev/null dump_A.dir
pg_restore -f /dev/null = dump_A.dir  0.28s user 0.21s system 47% cpu 1.042 = total

% time pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest
pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest  2.34s user 1.67s system 68% cpu 5.835 = total
% time pg_restore -f /dev/null = dump_A.dir
pg_restore -f /dev/null dump_A.dir  0.03s user = 0.22s system 22% cpu 1.118 total

64K = =3D=3D=3D
% time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir = evantest
pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest =  3.39s user 0.92s system 63% cpu 6.761 total
% time = pg_restore -f /dev/null dump_A.dir
pg_restore -f /dev/null = dump_A.dir  0.33s user 0.24s system 40% cpu 1.420 = total

% time pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest
pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest  2.35s user 1.74s system 69% cpu 5.849 = total
% time pg_restore -f /dev/null = dump_A.dir
pg_restore -f /dev/null dump_A.dir  0.04s user = 0.22s system 27% cpu 0.939 total

32K = =3D=3D=3D
% time pg_dump -Fd --compress=3Dlz4 -f dump_A.dir = evantest
pg_dump -Fd --compress=3Dlz4 -f dump_A.dir evantest =  3.43s user 0.94s system 58% cpu 7.416 total
% time = pg_restore -f /dev/null dump_A.dir
pg_restore -f /dev/null = dump_A.dir  0.34s user 0.22s system 56% cpu 0.983 = total

% time pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest
pg_dump -Fd --compress=3Dnone -f = dump_A.dir evantest  2.34s user 1.75s system 67% cpu 6.070 = total
% time pg_restore -f /dev/null = dump_A.dir
pg_restore -f /dev/null dump_A.dir  0.05s user = 0.23s system 29% cpu 0.926 = total

4k=3D=3D=3D=3D
% time pg_dump = -Fd --compress=3Dlz4 -f dump_A.dir evantest
pg_dump -Fd = --compress=3Dlz4 -f dump_A.dir evantest  3.45s user 0.94s system = 60% cpu 7.298 total
% time pg_restore -f /dev/null = dump_A.dir
pg_restore -f /dev/null dump_A.dir  0.37s user = 0.29s system 64% cpu 1.016 total

% time pg_dump = -Fd --compress=3Dnone -f dump_A.dir evantest
pg_dump -Fd = --compress=3Dnone -f dump_A.dir evantest  2.33s user 1.78s system = 69% cpu 5.947 total
% time pg_restore -f /dev/null = dump_A.dir
pg_restore -f /dev/null dump_A.dir  0.12s user = 0.29s system 40% cpu 1.009 = total
```

Best regards,
--
Chao Li (Evan)
HighGo Software = Co., Ltd.
https://www.highgo.com/




= --Apple-Mail=_4B380B2A-09F4-47E9-87BF-27A9F640DD9F--