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 1t2oNE-007Ppr-Hj for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Oct 2024 09:06:48 +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 1t2oNB-005ug1-JR for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Oct 2024 09:06:45 +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 1t2oNB-005ufD-9H for pgsql-hackers@lists.postgresql.org; Mon, 21 Oct 2024 09:06:45 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t2oN9-002CB6-Ta for pgsql-hackers@lists.postgresql.org; Mon, 21 Oct 2024 09:06:44 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5ebc9bda8c8so163523eaf.0 for ; Mon, 21 Oct 2024 02:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729501602; x=1730106402; darn=lists.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=OZSXvrmzuvYcDAi4FSINKxKmM193/oneHp+Rh0sbpRk=; b=NLwp0HyHAx3w+n03aLnn7cqxk/ZZmuj1nPTvalMP2V13JMWTOJVM1I2+TkNFoTShlQ gE+vmb9nnLN3FIAc/358bqitWTjbR3uP71DtsCId0WUlKOLCjGT2Ojpdl6pDKjVnH/06 EKVWRXCjPh7ELChFHOyyzKDRGLwcHBC0Zzy6U9AlgurvKZ3wTkr8FWayNtHfizyBY/Bz ppVNarnbbHiqVofvXo0VjLgfmAdWYtNpyCHKLRHqhZS5NTgfCkLt+Z1NO7oQVJvBT3vO a+460cKSTqe+NXCbslXqM/IN3ZfkxzTtEoOasa9zGZRQrni7HnskN2jMP1SF8kbijo1/ HYCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729501602; x=1730106402; 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=OZSXvrmzuvYcDAi4FSINKxKmM193/oneHp+Rh0sbpRk=; b=ka4bGHTLoGmg3Y0y9ZbywL/+hU1bZVu2Lq9Ydyrd9gXxt5dAVS0en8BSwb0NghyZI2 2Okl5VG8Q+Iac8iOsdZ1lPYUuavUvyZ2Q4NZTqmoX1aPScWKu9qo6zq5rxgOq5da0KXR qIDPDE/OI4Ri2RoCR6NtfnLVTEx2M/rH47ngIK6tgVxjoRB3FRizuEV9NLE70wxvTmnx CbLhil17N5cvFZwQLxi02EBj1NwS94Rq6maWbn7g7oAhDio/KSrmcGXbIwdnKybmI+GL UmdejUAuzIJW0q1vz1NEFJ5l/WNXZP2kUAOesWuGxYrorBhb/8cIhmGdUX72HCFH+j/9 Ub0A== X-Gm-Message-State: AOJu0Yzx9GedJhJ7N/FevyhmhzhkfnLbj91c8tSlYxithIHNcZxL1QkO dFB4G37nF+zxvM38UBeSdNXEos9qvX/1EJ37QznopO28V/MxTUSagQMTU4vmVA9TDEj5kQl4sRx fUKBR0X6bHS9KyOGp/3ye0mEXzDs= X-Google-Smtp-Source: AGHT+IGwCEAEOffj6znfUhdJ1GIfWx0Si37OWtWco7dMj6K+GP2m8kZilOi9il/eqx2bwCF+lWNeH+ejmdKltSpq4H8= X-Received: by 2002:a05:6820:1846:b0:5e1:ea03:928f with SMTP id 006d021491bc7-5eb8b7b39e6mr7713100eaf.7.1729501601999; Mon, 21 Oct 2024 02:06:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Mon, 21 Oct 2024 14:36:30 +0530 Message-ID: Subject: Re: Make default subscription streaming option as Parallel To: vignesh C Cc: PostgreSQL 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 On Mon, Oct 7, 2024 at 11:05=E2=80=AFAM vignesh C wro= te: > > The tests demonstrate a significant performance improvement when using > the parallel streaming option, insert shows 40-48 %improvement, delete > shows 34-39 %improvement, update shows 26-30 %improvement. In the case > of rollback the improvement is between 12-44%, the improvement > slightly reduces with larger amounts of data being rolled back in this > case. If there's a significant amount of data to roll back, the > performance of streaming in parallel may be comparable to or slightly > lower in some instances. However, this is acceptable since commit > operations are generally more frequent than rollback operations. > > One key point to consider is that the lock on transaction objects will > be held for a longer duration when using streaming in parallel. This > occurs because the parallel apply worker initiates the transaction as > soon as streaming begins, maintaining the lock until the transaction > is fully completed. As a result, for long-running transactions, this > extended lock can hinder concurrent access that requires a lock. > The longer-running transactions will anyway have a risk of deadlocks or longer waits if there are concurrent operations on the subscribers. However, with parallel apply, there is a risk of deadlock among the leader and parallel workers when the schema in publisher and subscriber is different. Say the subscriber has a unique constraint that the publisher doesn't have. See the comments in this regard atop applyparallelworker.c in the "Locking Considerations" section. Having said that, the apply workers will detect deadlock in such cases and will retry to apply the errored-out transaction. So, there is a self-healing in-built mechanism and in such cases, we anyway have a risk of UNIQUE_KEY conflict ERRORs which in most cases would require manual intervention. > Since there is a significant percentage improvement, we should make > the default subscription streaming option parallel. > This makes sense to me. I think it would be better to add a Note or Warning in the docs for the risk of deadlock when the schema of publisher and subscriber is not the same even though such cases should be less. --=20 With Regards, Amit Kapila.