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 1uC5gM-00AIzs-Vd for pgsql-hackers@arkaria.postgresql.org; Mon, 05 May 2025 23:57:11 +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 1uC5gK-00639k-4q for pgsql-hackers@arkaria.postgresql.org; Mon, 05 May 2025 23:57:08 +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 1uC5gJ-00639c-QB for pgsql-hackers@lists.postgresql.org; Mon, 05 May 2025 23:57:07 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uC5gG-000MAO-2r for pgsql-hackers@lists.postgresql.org; Mon, 05 May 2025 23:57:07 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-54c090fc7adso6173881e87.2 for ; Mon, 05 May 2025 16:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746489424; x=1747094224; 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=z669E+IhbHUdoKd9FlA2KQO554tdJuR1HhULlVpkSn0=; b=CEG0hEf9LcUXmiqS+0GwGRXQhrsRF/FBSILY2KsKhy0vZtRLbpJAxYj9EWlAM8yVHv d9mgz/DAKgemVTnlKCv03Ai1LY+7ws1QgQXK1J6Gvz1AsBUt29CIdhhDJeyvDDMWpf0W iRVfIdtbq9z/VzhrVxL8cvpvDuqabxWUx2hv3AHZNJAb7GQGlSFW4WbpITcahJlE82zL sPDjSglsldBny3YBlKi6WXKpnZcEWCJI9gVewWmdnDu5rk1YW+vQuL/RJigcnMW3x4wY t8A6NSjvkaR2wCpNQakFi35f6GCl9r2y5ivPzW2vSGxvoygiUp1DSYJ+qx84hB990d2e 43fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746489424; x=1747094224; 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=z669E+IhbHUdoKd9FlA2KQO554tdJuR1HhULlVpkSn0=; b=SmRSIO5iMXvtv4Ponx3eLcbXmsKy7ck8b6f72BTnxjyiesQtPqtwy0T0rc8bPJ1WKJ DC1Bd7eYR761UEvtSfqqKXplr4iuWDQmRI2kLJg3mzZDUrGov2aTqKI35uKOw1FPFu3t mPErs8B8nPmF0br3oSh99h33riXQkF5fFBIXVbWkqsR/9/3KmdBoyrmRx9W9WFTu7Utv BxVPaHxhYY6rJkkSUfnMdfU0mjfMh5D8JRGx+C+5eJ0nDwdo3KleCfR3/SimYSzZEI3J sBIjP/eyCzMHu+YztoCphqerfWgejrmHeXq3AMAych3g0Ya5gpmlh7opRW73+pfMHVcl jcIA== X-Forwarded-Encrypted: i=1; AJvYcCW7jaznPtpbRsxe2IZrB64dN9wYZ4ARhT4A6Pc5JTGZDbd3sUNPko6MWjXYTI68Lq+zv39BSKTEOreTLZvG@lists.postgresql.org X-Gm-Message-State: AOJu0Yz2sFfEmjKKW8TpiXwiPMBVnF7ML31rlOGhFsQL/1RDW+9zFtuw JaiM+2OYeAhwaHL7VjvDBbu4Kj04XSbpioOVuIPS46PkwTDhWIuOSl3m5OYGBiY7egzI1Kb7l6v HzcZ9jvgHcfPGfdZmWRn6EkodWU4= X-Gm-Gg: ASbGnctGe3Z9zn12168aOUfa10/uH/MpCUmz87+eBsKnINUd6s23hfJr0NkSfE2ucix kBHXHdfvD7WlNgFJdoj6E41ZnrJFhJmEJOpRzD35tIZ/c4YuDPNKIpiIfxi+rJQuBFe9a5CfzVT ArL2EexlbOjn85L2X1mwuGB7KWJzhJ8AFZUw== X-Google-Smtp-Source: AGHT+IFpIGQEtJIIh8SaAI754BALqumhPwTM5rs1dRG2N6hGNq3wUt3veDL4vIXsKTao1BXiZFjENKzmh7OeOv5tais= X-Received: by 2002:a05:6512:398c:b0:549:8db6:b2d9 with SMTP id 2adb3069b0e04-54fa4d56278mr2191415e87.27.1746489423853; Mon, 05 May 2025 16:57:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Mon, 5 May 2025 16:56:27 -0700 X-Gm-Features: ATxdqUFn_Y3mHJCze-k2COxu2uX-xgXaF1rARcnV_L_qzKr-GahVIZ1fWanwJNs Message-ID: Subject: Re: POC: Parallel processing of indexes in autovacuum To: Daniil Davydov <3danissimo@gmail.com> Cc: Maxim Orlov , Postgres 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 Sat, May 3, 2025 at 1:10=E2=80=AFAM Daniil Davydov <3danissimo@gmail.com= > wrote: > > On Sat, May 3, 2025 at 5:28=E2=80=AFAM Masahiko Sawada wrote: > > > > > In current implementation, the leader process sends a signal to the > > > a/v launcher, and the launcher tries to launch all requested workers. > > > But the number of workers never exceeds `autovacuum_max_workers`. > > > Thus, we will never have more a/v workers than in the standard case > > > (without this feature). > > > > I have concerns about this design. When autovacuuming on a single > > table consumes all available autovacuum_max_workers slots with > > parallel vacuum workers, the system becomes incapable of processing > > other tables. This means that when determining the appropriate > > autovacuum_max_workers value, users must consider not only the number > > of tables to be processed concurrently but also the potential number > > of parallel workers that might be launched. I think it would more make > > sense to maintain the existing autovacuum_max_workers parameter while > > introducing a new parameter that would either control the maximum > > number of parallel vacuum workers per autovacuum worker or set a > > system-wide cap on the total number of parallel vacuum workers. > > > > For now we have max_parallel_index_autovac_workers - this GUC limits > the number of parallel a/v workers that can process a single table. I > agree that the scenario you provided is problematic. > The proposal to limit the total number of supportive a/v workers seems > attractive to me (I'll implement it as an experiment). > > It seems to me that this question is becoming a key one. First we need > to determine the role of the user in the whole scheduling mechanism. > Should we allow users to determine priority? Will this priority affect > only within a single vacuuming cycle, or it will be more 'global'? > I guess I don't have enough expertise to determine this alone. I will > be glad to receive any suggestions. What I roughly imagined is that we don't need to change the entire autovacuum scheduling, but would like autovacuum workers to decides whether or not to use parallel vacuum during its vacuum operation based on GUC parameters (having a global effect) or storage parameters (having an effect on the particular table). The criteria of triggering parallel vacuum in autovacuum might need to be somewhat pessimistic so that we don't unnecessarily use parallel vacuum on many tables. > > > > About `at_params.nworkers =3D N` - that's exactly what we're doing (y= ou > > > can see it in the `vacuum_rel` function). But we cannot fully reuse > > > code of VACUUM PARALLEL, because it creates its own processes via > > > dynamic bgworkers machinery. > > > As I said above - we don't want to consume additional resources. Also > > > we don't want to complicate communication between processes (the idea > > > is that a/v workers can only send signals to the a/v launcher). > > > > Could you elaborate on the reasons why you don't want to use > > background workers and avoid complicated communication between > > processes? I'm not sure whether these concerns provide sufficient > > justification for implementing its own parallel index processing. > > > > Here are my thoughts on this. A/v worker has a very simple role - it > is born after the launcher's request and must do exactly one 'task' - > vacuum table or participate in parallel index vacuum. > We also have a dedicated 'launcher' role, meaning the whole design > implies that only the launcher is able to launch processes. > > If we allow a/v worker to use bgworkers, then : > 1) A/v worker will go far beyond his responsibility. > 2) Its functionality will overlap with the functionality of the launcher. While I agree that the launcher process is responsible for launching autovacuum worker processes but I'm not sure it should be for launching everything related autovacuums. It's quite possible that we have parallel heap vacuum and processing the particular index with parallel workers in the future. The code could get more complex if we have the autovacuum launcher process launch such parallel workers too. I believe it's more straightforward to divide the responsibility like in a way that the autovacuum launcher is responsible for launching autovacuum workers and autovacuum workers are responsible for vacuuming tables no matter how to do that. > 3) Resource consumption can jump dramatically, which is unexpected for > the user. What extra resources could be used if we use background workers instead of autovacuum workers? > Autovacuum will also be dependent on other resources > (bgworkers pool). The current design does not imply this. I see your point but I think it doesn't necessarily need to reflect it at the infrastructure layer. For example, we can internally allocate extra background worker slots for parallel vacuum workers based on max_parallel_index_autovac_workers in addition to max_worker_processes. Anyway we might need something to check or validate max_worker_processes value to make sure that every autovacuum worker can use the specified number of parallel workers for parallel vacuum. > I wanted to create a patch that would fit into the existing mechanism > without drastic innovations. But if you think that the above is not so > important, then we can reuse VACUUM PARALLEL code and it would > simplify the final implementation) I'd suggest using the existing infrastructure if we can achieve the goal with it. If we find out there are some technical difficulties to implement it without new infrastructure, we can revisit this approach. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com