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 1pIS4Q-0004PL-PG for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jan 2023 10:22:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pIS4P-0005hy-1O for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jan 2023 10:22:57 +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 1pIS4O-0005hp-LA for pgsql-hackers@lists.postgresql.org; Thu, 19 Jan 2023 10:22:56 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pIS4H-0007yt-25 for pgsql-hackers@lists.postgresql.org; Thu, 19 Jan 2023 10:22:55 +0000 Received: by mail-wm1-x334.google.com with SMTP id o17-20020a05600c511100b003db021ef437so873076wms.4 for ; Thu, 19 Jan 2023 02:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VLhMnL7dMjdpBBvqByKdz7GHGl5Y2QVIh8kFitT+KW8=; b=n5TlbMZ2jfAH5hU+rAou7TJt7M9VXp9+0N12IMcr1HzTIqxthJb5Tw85R3ST2OsK8d VBQ7cFlvCbeyLhv18D3xFIUoS7Mk626Vo8nT+D4/dLZ+RgIBWGTj/L+13j8FqN4nnLgz XC8LqJZIhvdGz2yvJcwABDlIgsC3CuyyM7n3MhDkYcU8iT6x5suDttnqxvMBrXMclbFD D5da3DY4eqBcXZ7H1t1eWHASn3YmihaqszOjAkmQyYQ0xtYT16+ivtEtfzbeGJcisem1 no1WOT+UhrV8sLxl7IQqJyUpn/xRzPcjeryMA6OteHk/Ap+Bd6zAKdEBclFjKTI2uGjc fF7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=VLhMnL7dMjdpBBvqByKdz7GHGl5Y2QVIh8kFitT+KW8=; b=zNpXtwPAYUIvV9Gihsr7LTpxPtLeV3PgmEnI/hUs0FxrHF60azupTpKA1n0V6zvIbm UIxxWMTXXz1jnOyASes9+UyagUeyJSp/t1ABMR/i8bEo1wyqmQsz5GpFeuOZoWgoK5Z5 yn6PGLcgkS9efNGOMn3dwXYij9Xk17zONj1x32ydCUiJRj09AaryVY+M9IMvHdUVKhB4 RPEgUXPuvGGR7lrrHZDUofIGWzC2S1SwKwc/UEEdmzPLtk7xK2s8wvlAuf/k4hC9o/VZ J8AbO96Y/QRflsmDR5oeCvdWYKegbi+GngOtJRTCRdbl2M+pybkHqqnuE6SUHNxJhRXF UvLQ== X-Gm-Message-State: AFqh2kosfBpz7jvl3fJKTAVLJPWy6Mq8KK8xQpzju+QJw654xTfUzvx5 nnMAbUrW3zHOWKWAqF/5CytCflBc79UheAT7g2k= X-Google-Smtp-Source: AMrXdXulPrTKAppp2LLLjp5JeZcEqQ6RXixAJEXt5qzs9EO1eJ/35OJSjfLNmvhJNnoY2Tbi4R7QprVzAl1Rc0Tn1/8= X-Received: by 2002:a05:600c:3d05:b0:3d9:fae2:344b with SMTP id bh5-20020a05600c3d0500b003d9fae2344bmr560482wmb.105.1674123768170; Thu, 19 Jan 2023 02:22:48 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Thu, 19 Jan 2023 15:52:36 +0530 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: Amit Kapila Cc: Peter Smith , "houzj.fnst@fujitsu.com" , Masahiko Sawada , "wangw.fnst@fujitsu.com" , "shiy.fnst@fujitsu.com" , PostgreSQL Hackers , Dilip Kumar , shveta malik Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 19, 2023 at 3:44 PM shveta malik wrote: > > On Thu, Jan 19, 2023 at 11:11 AM Amit Kapila wrote: > > > > On Wed, Jan 18, 2023 at 12:09 PM Amit Kapila wrote: > > > > > > On Fri, Jan 13, 2023 at 11:50 AM Peter Smith wrote: > > > > > > > > Here are some review comments for patch v79-0002. > > > > > > > > > > So, this is about the latest v84-0001-Stop-extra-worker-if-GUC-was-changed. > > > > > > > > > > > I feel this patch just adds more complexity for almost no gain: > > > > - reducing the 'max_apply_workers_per_suibscription' seems not very > > > > common in the first place. > > > > - even when the GUC is reduced, at that point in time all the workers > > > > might be in use so there may be nothing that can be immediately done. > > > > - IIUC the excess workers (for a reduced GUC) are going to get freed > > > > naturally anyway over time as more transactions are completed so the > > > > pool size will reduce accordingly. > > > > > > > > > > I am still not sure if it is worth pursuing this patch because of the > > > above reasons. I don't think it would be difficult to add this even at > > > a later point in time if we really see a use case for this. > > > Sawada-San, IIRC, you raised this point. What do you think? > > > > > > The other point I am wondering is whether we can have a different way > > > to test partial serialization apart from introducing another developer > > > GUC (stream_serialize_threshold). One possibility could be that we can > > > have a subscription option (parallel_send_timeout or something like > > > that) with some default value (current_timeout used in the patch) > > > which will be used only when streaming = parallel. Users may want to > > > wait for more time before serialization starts depending on the > > > workload (say when resource usage is high on a subscriber-side > > > machine, or there are concurrent long-running transactions that can > > > block parallel apply for a bit longer time). I know with this as well > > > it may not be straightforward to test the functionality because we > > > can't be sure how many changes would be required for a timeout to > > > occur. This is just for brainstorming other options to test the > > > partial serialization functionality. > > > > > > > Apart from the above, we can also have a subscription option to > > specify parallel_shm_queue_size (queue_size used to determine the > > queue between the leader and parallel worker) and that can be used for > > this purpose. Basically, configuring it to a smaller value can help in > > reducing the test time but still, it will not eliminate the need for > > dependency on timing we have to wait before switching to partial > > serialize mode. I think this can be used in production as well to tune > > the performance depending on workload. > > > > Yet another way is to use the existing parameter logical_decode_mode > > [1]. If the value of logical_decoding_mode is 'immediate', then we can > > immediately switch to partial serialize mode. This will eliminate the > > dependency on timing. The one argument against using this is that it > > won't be as clear as a separate parameter like > > 'stream_serialize_threshold' proposed by the patch but OTOH we already > > have a few parameters that serve a different purpose when used on the > > subscriber. For example, 'max_replication_slots' is used to define the > > maximum number of replication slots on the publisher and the maximum > > number of origins on subscribers. Similarly, > > wal_retrieve_retry_interval' is used for different purposes on > > subscriber and standby nodes. > > > > [1] - https://www.postgresql.org/docs/devel/runtime-config-developer.html > > > > -- > > With Regards, > > Amit Kapila. > > Hi Amit, > > On rethinking the complete model, what I feel is that the name > logical_decoding_mode is not something which defines modes of logical > decoding. We, I think, picked it based on logical_decoding_work_mem. > As per current implementation, the parameter 'logical_decoding_mode' > tells what happens when work-memory used by logical decoding reaches > its limit. So it is in-fact 'logicalrep_workmem_vacate_mode' or Minor correction in what I said earlier: As per current implementation, the parameter 'logical_decoding_mode' more or less tells how to deal with workmem i.e. to keep it buffering with txns until it reaches its limit or immediately vacate it. > 'logicalrep_trans_eviction_mode'. So if it is set to immediate, > meaning vacate the work-memory immediately or evict transactions > immediately. Add buffered means the reverse (i.e. keep on buffering > transactions until we reach a limit). Now coming to subscribers, we > can reuse the same parameter. On subscriber as well, shared-memory > queue could be considered as its workmem and thus the name > 'logicalrep_workmem_vacate_mode' might look more relevant. > > On publisher: > logicalrep_workmem_vacate_mode=immediate, buffered. > > On subscriber: > logicalrep_workmem_vacate_mode=stream_serialize (or if we want to > keep immediate here too, that will also be fine). > > Thoughts? > And I am assuming it is possible to change the GUC name before the > coming release. If not, please let me know, we can brainstorm other > ideas. > > thanks > Shveta thanks Shveta