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.96) (envelope-from ) id 1wceoG-003WIa-0j for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2026 07:47:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wceoD-004MMJ-1y for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2026 07:47:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wceoD-004MMB-0d for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2026 07:47:37 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wceoA-000000009da-3qd6 for pgsql-hackers@postgresql.org; Thu, 25 Jun 2026 07:47:35 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-bebb72b845aso424446666b.3 for ; Thu, 25 Jun 2026 00:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782373653; cv=none; d=google.com; s=arc-20260327; b=nZY7H1rfLay6DYbxogx/pVryMrvAXHt2fg44c402eef9VoeqsatmhYOzccCC2p8NDU qYZ23hUDcMfzenUmDjdiORazdOAqOJh2bHJmHsk+3wzQc9Ew1dDNyPPBzPKgvyLxWKUv aHbo00/7EQDOhnVdDm160NXc/4CPT1kBWJbFogfYxbZw1fGY5Mj3y9TEv6mhjtOmrjw3 E6mnqb7f22O5iLSCKcBIJAr1A6REayhS07pfQfJdyQOOWK5MWr2c5j3m35jzrRDQSdpB T5kAkSOfh7jEKSI32mkdzmjGoaJY8OAO/K5wZveXoRZMqah/ap3AGg+V9GESbh0eOUSp K3IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=BOQyBW1PEBJy2nO6/ExFtRm8D9yN1ZmoLbPlf+kqHcw=; fh=amOhUw54LJBCSQEHHxDEzsmuXJu88/MEx6vfbkYB4ps=; b=B4UWPhRtL8dGi3XZkzYqKQPsMRr6kIHshRylQb/6KFRu8+6zrCOmvQ5eOsIeSf1amK dsiZPUi5IAqFwt79nMUubDqtkS/8xQ9OlgDX3JjicCTaMArNvFLJGtYG2097rruoomm/ 3TVWe/DfBii1SFkNRWyslsysj/Qd5Rtwv4T45dwzUFXjCN0o9MB3Mu1LXIyZXwSgPCKv PLGGTBPXw17hwO7kgKhYfpxmEyxd+3XJE7lKJdrSzfBjcKMxx4IbgInimfRErIwa8F1g QdMkcmfc0/9m7JixrJrhyYjtYSKpm3Ee3bH4bBp0xbffVMu1TARXqt/H4Du57YyKrMub DGyw==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782373653; x=1782978453; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BOQyBW1PEBJy2nO6/ExFtRm8D9yN1ZmoLbPlf+kqHcw=; b=Fme0gQvvNWNDlIQE1L9Gb95Lc7CT7UxxehyX81Nf2D4U9S7aFLm9WIAcxiy6+uQdR+ kreI9yrYvs/XM/ELPfBvoTv593G3TPTkIwAsGaoC4kXvlJ42KJpfDd25zzRvvW68A3Ur +xd+e4WR7JMrVONsCzeFtpKEfwTGpcAzHJCDgo2YRBLtkXRolVWd6VeeijtMf0duKQoE xc7m9TJy28+z7e9JFfiLJxNxRkmsbvGEism/i4t6V6ZBRnKgj5Hx+TEG6DAcK+DX8nof 8kcEvniPzM9P3CocfY+Z7nBfDPKRkfPNPSlxBnL/Z4M7xIg4gwjRtCJMhA7lfZDoJMSF WQ6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782373653; x=1782978453; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BOQyBW1PEBJy2nO6/ExFtRm8D9yN1ZmoLbPlf+kqHcw=; b=rYQyINQVm7kvoOqM+5uunxJU9n9eO/iq31BtVPDM1O2Jg+NSk+bGa0a+EsSwBD0Jao WhOu3ijh5QzTKUemvOnPdZ2R2MtoH679p0gPVbwfcggTAoKhnfrHmCrndL+Jm8vOTwfV sa5JNkaBI0XIf8Zrbt0nuLn0YugJkRskaEDl8j/0z5qo97GmXUWc6ze5y4nubipnMkAE cvQVK8BEQxs7cn8eH6/ilrbmu6NhEVjYOUiU0mHlw8o+r6i93uCd6wHlGswdzTxBNlD6 rGYg7ffvKYOXLJNyTWi8iz4daIVeugsKVeHyo0Zn66zOHaBdeg/nznj8vH6fyI7d5Sdf yh1g== X-Forwarded-Encrypted: i=1; AHgh+RpcIa1zVoC7Tw8OzqDhQcjUR02Z0eo36TEBb/lR9cLeDyPYQsaV4U5R8otR6EtCIeks5A6hsi1J02lPwWsT@postgresql.org X-Gm-Message-State: AOJu0Yxsb/0pQABTVilIAf/HYII3EYApMi4inbYSJs+6nGEhjR5G2hg0 +Cz7VirHFvwmpr0++/p/SDW7lLaQdZq8eLEB2ybLqUUfxTLyg1syNtM24sS82Mw/Izq5d8FGUiY fqyuRJV/DqNHuVByHvV77jgyJqAOQCzA= X-Gm-Gg: AfdE7ckF/NqqlTOLqYOvNdlU8CltLd86Q7IxLWyFPvGpvAfcE9e+umdMrihRNyAuD4D 2ZQMK1VmdwHUmai7CkC/om/Yak40EsN3WlprOdYBPcxEVkxsG/T71lakOVo4F2rHepXhw3UjxzV CLzaI4eDMCMY44kBze4x7TMvFpeEUSaGLusyhHpxhaZ90MvIdIPc9VdpvNf0zBdPqFCKyn2qGmG yj/IC6JVw+XkfBiKR+HicR+BgLl8gUSlYhsSNMHBMeiqv3v7KzpkqaHsZybAaAaosXhOJaOdRHo mlv6leGZaiUg0vVR0QKCfm1LwPiPoDBPsQk6jlOzr93+0JcYYhuExL2QfbAm2/ZfGSJeMLw/oqE 7wxdotlefwLbZ8ZBldz7lNICnOic= X-Received: by 2002:a17:906:2083:b0:c12:d64:ca50 with SMTP id a640c23a62f3a-c120d64cbc6mr6736966b.16.1782373652849; Thu, 25 Jun 2026 00:47:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Xuneng Zhou Date: Thu, 25 Jun 2026 15:47:20 +0800 X-Gm-Features: AVVi8Ce4P5pkhb-AIr-CRmH-tjt4_Cmp20xHYdbDLeaZY3_1UqTALlxVemDg8Jo Message-ID: Subject: Re: [WIP] Pipelined Recovery To: Imran Zaheer Cc: assam258@gmail.com, Zsolt Parragi , Jakub Wartak , "Hayato Kuroda (Fujitsu)" , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Imran, On Tue, Jun 23, 2026 at 9:27=E2=80=AFPM Imran Zaheer = wrote: > > Hi > > I am attaching the new series of patches. > > What has changed? > > * Rebased > > * The patch set is now split into two new patches. This will make the > code easier to understand and review. > > * The v4-0003 patch contains code mostly related to keeping the > recovery states synced between the startup process and the pipeline > process. Most of these changes were required to make the streaming > replication work. > > * The v4-0002 patch now only contains the consumer code that handles > receiving the decoded records from the shmem queue and moving the redo > loop forward. > > * The v4-0004 contains some basic tests to see if the pipeline worker > is functioning as expected. More testing was done by passing > PG_TEST_INITDB_EXTRA_OPTS=3D"-c wal_pipeline=3Don" before running the > recovery test suite. +1 for splitting the patch set into smaller components to make the review process smoother. > * Other than that, the cpu overhead during deserialization is > optimized by skipping multiple copies of the decoded record and > directly passing the pointer to the shmem queue. There is still some > overhead visible during serialization that could be improved at the > producer end. > > * Signal handling for the pipeline worker is improved so that > promotion signals are sent to both the startup process and the > producer worker by the postmaster. > > > You will also find the new benchmarks attached [1] and the pdf report > overview. A simple cpu profiling on the pipelined startup process > shows that the cpu overhead during reading records has now been > removed and offloaded to the producer worker. > > Before pipelining: > > Around 50% of the cpu time is spent on fetching the wal record. Note that > in this workload pipeline is off so don't worry about the new func > ReceiveRecord(), it's just a wrapper around ReadRecord(). > > Children Self Command Shared O Symbol > - 98.85% 0.21% postgres postgres [.] PerformWalRecovery > - 98.64% PerformWalRecovery > - 51.00% ReceiveRecord > - 50.78% ReadRecord > - 50.52% XLogPrefetcherReadRecord > - 49.61% XLogPrefetcherNextBlock > + 25.33% XLogReadAhead > + 22.32% PrefetchSharedBuffer > + 0.76% smgropen > - 46.68% ApplyWalRecord > + 29.23% heap_redo > + 9.51% heap2_redo > + 4.74% btree_redo > + 1.11% xlog_redo > + 0.80% xact_redo > > > After Pipelining: > > Here the only work needed to be done by the cpu is to get the decoded > record from > the queue. Other times (89.13%) cpu is worried about applying the wal rec= ord. > > Children Self Command Shared O Symbol > - 98.74% 0.37% postgres postgres [.] PerformWalRecovery > - 98.37% PerformWalRecovery > - 89.13% ApplyWalRecord > + 56.89% heap_redo > + 18.28% heap2_redo > + 8.01% btree_redo > + 2.02% xlog_redo > + 1.15% xact_redo > - 7.80% ReceiveRecord > + 7.63% WalPipeline_ReceiveRecord > > If the recovery process is not I/O bound then we would be able to test > this cpu optimization. Doing pgbench on a workload that is fully in > memory shows around 30% performance gains. You can see more > benchmarking details in the attached drive link [1] The perf result looks promising! > Some comments related to attached pdf and benchmarking, it is showing > that we can get more performance advantage out of the pipeline when > most of the workload is running in memory i.e. we have enough shared > buffers configured. > > If you want to do some experiments, please be my guest; I would be > happy to see more testing. You can share what performance advantage > you are getting from this. You can also refer to the benchmarking > script that I have been using [2]. > > > Looking forward to your review, comments, etc. I haven't had a chance for a meaningful review yet, but expect to do so soo= n. -- Regards, Xuneng Zhou HighGo Software Co., Ltd.