Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pwyMx-00036c-29 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 May 2023 04:57:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pwyMw-0006o8-00 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 May 2023 04:57:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pwyMv-0006nx-N6 for pgsql-hackers@lists.postgresql.org; Thu, 11 May 2023 04:57:33 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pwyMs-001uY3-S9 for pgsql-hackers@postgresql.org; Thu, 11 May 2023 04:57:33 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f13cd0c4b3so1529186e87.0 for ; Wed, 10 May 2023 21:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683781050; x=1686373050; 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=D9jRvPxIYxlR5K3dbMBN8mHL7trOld2VXYpMzDG6smg=; b=f/qWExNfPzPZF2wPp5hoyWBcyRZvblkQGF6RQsgxikLspWugKA7dyhv58tpfAJYBQ5 KZJc91CN126+1VlnNvofpCfuFTWpEL8VfklZ9ND1hmHeymjrZnjwmLZsoOMx/GkQQYM3 ggwTGrWAI/8tp9p4vidsI+Pq0VM/PJjO6K5W8S5O56/CLbBw58zkIEwxGxjRj/hub5cb iC7m3PsoKOI/SIG61Hsrdc8lCkWfroE+uigc/ijec8obF5UMjQ9Ry/MCnOh7PFF+Ds3V jX8FUsa1rwI47vWl/7/ai6EAjPoXJgcJiDmodK9svDFa7gKVOnM9xcriqHLWgkYSOX+V Nicg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683781050; x=1686373050; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D9jRvPxIYxlR5K3dbMBN8mHL7trOld2VXYpMzDG6smg=; b=e703Qes/KKRWrGpzrboAE/YbtNYMs+pw8exLEtAQCzpv/kxQFHUiWtPgEudAycmMyk 2mbP9mptJkGIfLRaQ15vdPiiZReK6ARnNPXRwt2KhA9E4lBPOR9o7FjVFZkcuQVGNdKP t16w8SG+HvQnIB1fmONhm9jcNAJLC6rQKmIWHNpdU9SOdmnSP4mdjAdSPTk3QlYWYIuf yMnQJPizAkLv894U0s/TZvefSRcJ0br+apk7h0+yiDkGqcdC20qgGQtYUoIYk1cvWkgE gzQPr2w2mRzl+vsl2hnK3HIACJGioPHvpInZV6P3xD4nSSqWfw9RNhKs1RyTSQD8tCSw YjJg== X-Gm-Message-State: AC+VfDziagF/GVuv/JuyPts0N0gdPxep9RkAXHrJhby8B8knk3X3+k+c MkN9bR2Ye5nHiqNgHlHDmxYJ6mmZ7qfMuSiT4TU= X-Google-Smtp-Source: ACHHUZ4ObRQUGLsD05RzGGcfhEPqbUXbKx9hdp4vtutN3uEoBGhbCZKrx4bSUs0rOIXJaBwG1AHcarcE6jm0srqI6FA= X-Received: by 2002:ac2:5451:0:b0:4f1:3d76:d1a2 with SMTP id d17-20020ac25451000000b004f13d76d1a2mr4759034lfn.0.1683781050050; Wed, 10 May 2023 21:57:30 -0700 (PDT) MIME-Version: 1.0 References: <20230509190247.3rrplhdgem6su6cg@awork3.anarazel.de> In-Reply-To: From: Masahiko Sawada Date: Thu, 11 May 2023 13:56:52 +0900 Message-ID: Subject: Re: walsender performance regression due to logical decoding on standby changes To: Amit Kapila Cc: "Zhijie Hou (Fujitsu)" , Bharath Rupireddy , "pgsql-hackers@postgresql.org" , "Drouvot, Bertrand" , Jeff Davis , Robert Haas , Andres Freund 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 On Wed, May 10, 2023 at 7:33=E2=80=AFPM Amit Kapila wrote: > > On Wed, May 10, 2023 at 3:41=E2=80=AFPM Zhijie Hou (Fujitsu) > wrote: > > > > On Wednesday, May 10, 2023 2:36 PM Bharath Rupireddy wrote: > > > > > > > > > > My current guess is that mis-using a condition variable is the best= bet. I > > > > think it should work to use ConditionVariablePrepareToSleep() befor= e a > > > > WalSndWait(), and then ConditionVariableCancelSleep(). I.e. to neve= r use > > > > ConditionVariableSleep(). The latch set from ConditionVariableBroad= cast() > > > > would still cause the necessary wakeup. > > > > > > How about something like the attached? Recovery and subscription test= s > > > don't complain with the patch. > > > > Thanks for the patch. I noticed one place where the logic is different = from before and > > just to confirm: > > > > if (AllowCascadeReplication()) > > - WalSndWakeup(switchedTLI, true); > > + ConditionVariableBroadcast(&WalSndCtl->cv); > > > > After the change, we wakeup physical walsender regardless of switchedTL= I flag. > > Is this intentional ? if so, I think It would be better to update the c= omments above this. > > > > This raises the question of whether we need this condition variable > logic for physical walsenders? It sounds like a good idea. We can have two condition variables for logical and physical walsenders, and selectively wake up walsenders sleeping on the condition variables. It should work, it seems like much of a hack, though. Regards, [1] https://www.postgresql.org/message-id/2d314c22b9e03415aa1c7d8fd1f698dae= 60effa7.camel%40j-davis.com --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com