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 1p6W7o-0001rM-MV for pgsql-hackers@arkaria.postgresql.org; Sat, 17 Dec 2022 12:17:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p6W6o-0006vI-Ob for pgsql-hackers@arkaria.postgresql.org; Sat, 17 Dec 2022 12:16:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6W6o-0006v9-5B for pgsql-hackers@lists.postgresql.org; Sat, 17 Dec 2022 12:16:06 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p6W6j-0007h6-A5 for pgsql-hackers@lists.postgresql.org; Sat, 17 Dec 2022 12:16:04 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-43ea87d0797so40673927b3.5 for ; Sat, 17 Dec 2022 04:16:01 -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=E/z7v5OAW2H4VchNjUuKz0rsSagi0aQAP0f9nC911gc=; b=Cd6QoW4GAM2FnZwXLmS9RPYZfrR6eqAZiiN57So9D5VtGGZoxO2+CSe/5+4hka0dfy MP9zuPYLWJ2vAIYXP8QQLnU2w4i6xFYE4E1FZTZRsrV7yBsu7P/uueyqYQbbXzUwZ1nZ 48oBCO9E69y4O8uv31N8/0euOnKWEHhjXu9aoLEhDrrn2L+imzm4zz6LXuFq2ki++ctW /K4Q70z8NhF7Xs0TrVYIi0EUqHhRUw3YUtdJLYjKWs0jvJ0VRJkq/p2rvTRie8mwoJAX 42YzzMeFucrbKl9eWV+ThJ2R2SVX3Ryk/OWAuvRKFk+G9PQftZOTfwidLFEUKZ+aHclp ySGA== 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=E/z7v5OAW2H4VchNjUuKz0rsSagi0aQAP0f9nC911gc=; b=i6kx7SQwd5mU+jRSHIvkJ9ayVQ6y1vT5AYpFuE/sllgN0G/10OPAdcyF/Yqq18RCBc 2qbTARAzc7Z6MlI1pdK6VC/cjydp9nF5YmTeF+82LxLvLJ028n4FRUflUlCGoLe17CxH 0OdmQ/BTBths07YNA4gvvhRZd/8RYnw3GSRb2cn6c6uneC8WhdijtaABCwMu3JSVM496 dnQZBi1NL/7GEjcFqNuJ9yU2VGMaZSJ//Jv43YtoLKYuNeF02SpYJC9yWApOfCM7sf4/ 1R8cH2h1ulJYZlNYrfX6E1unEkmCvjWKEWUqPCYjtLc5mR85nI9iHkr/LuTtewXge+VU b/kg== X-Gm-Message-State: ANoB5pkd9na/rYDELxZ+FxTQEQ03+3jdOG2PTXa6itqIZrh4jsZD2ALr Jw5yCOsnFPKqUnWoFnbFvrUMZm89ekWvkQoIr14= X-Google-Smtp-Source: AA0mqf6F5DiGGIme35tM3F1OU8Mq4YmxFxGoUP1LcdJapMCQWWwhej6pLrk+aA7VUZJhVwUUzMUBA7D6r9kfHHczEQI= X-Received: by 2002:a05:690c:b93:b0:3bc:d08e:34c4 with SMTP id ck19-20020a05690c0b9300b003bcd08e34c4mr2510364ywb.305.1671279360114; Sat, 17 Dec 2022 04:16:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Sat, 17 Dec 2022 17:45:50 +0530 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: "houzj.fnst@fujitsu.com" Cc: Masahiko Sawada , "wangw.fnst@fujitsu.com" , Peter Smith , Dilip Kumar , "shiy.fnst@fujitsu.com" , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Dec 16, 2022 at 4:34 PM Amit Kapila wrote: > > On Fri, Dec 16, 2022 at 2:47 PM houzj.fnst@fujitsu.com > wrote: > > > > > --- > > > + active_workers = list_copy(ParallelApplyWorkerPool); > > > + > > > + foreach(lc, active_workers) > > > + { > > > + int slot_no; > > > + uint16 generation; > > > + ParallelApplyWorkerInfo *winfo = > > > (ParallelApplyWorkerInfo *) lfirst(lc); > > > + > > > + LWLockAcquire(LogicalRepWorkerLock, LW_SHARED); > > > + napplyworkers = > > > logicalrep_pa_worker_count(MyLogicalRepWorker->subid); > > > + LWLockRelease(LogicalRepWorkerLock); > > > + > > > + if (napplyworkers <= > > > max_parallel_apply_workers_per_subscription / 2) > > > + return; > > > + > > > > > > Calling logicalrep_pa_worker_count() with lwlock for each worker seems > > > not efficient to me. I think we can get the number of workers once at > > > the top of this function and return if it's already lower than the > > > maximum pool size. Otherwise, we attempt to stop extra workers. > > > > How about we directly check the length of worker pool list here which > > seems simpler and don't need to lock ? > > > > I don't see any problem with that. Also, if such a check is safe then > can't we use the same in pa_free_worker() as well? BTW, shouldn't > pa_stop_idle_workers() try to free/stop workers unless the active > number reaches below max_parallel_apply_workers_per_subscription? > BTW, can we move pa_stop_idle_workers() functionality to a later patch (say into v61-0006*)? That way we can focus on it separately once the main patch is committed. -- With Regards, Amit Kapila.