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 1paTPR-00049S-2A for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Mar 2023 03:27:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1paTPO-0002Qd-BX for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Mar 2023 03:27:06 +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 1paTPO-0002QU-0Y for pgsql-hackers@lists.postgresql.org; Fri, 10 Mar 2023 03:27:06 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1paTPK-0002mp-M1 for pgsql-hackers@postgresql.org; Fri, 10 Mar 2023 03:27:05 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id t5-20020a4ac885000000b005251f70a740so611519ooq.8 for ; Thu, 09 Mar 2023 19:27:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678418820; 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=fJCP5DpsUq8WkHYd2XyUpcCVaPjbDmPbS+iSJ8cOURA=; b=Qwh36440Mff3VNwK/D91ypS3aeFRWzHfM1sTHpiXwP82NiYY6Ps8HVJFnc7Fq8ruAA B6CfoZN0EKrQ85pMGw0QL7nJ7TCeAnwALU6Cjo8uEcC7SBWPUm5Jc4X9kXzlOdd850tb EEoV6rLc5dXd3BQCEJErAQ6GgvdFdOwV3HrwDJ6ZKsKZUQd2YgAHf1tfgX6+6qTARUZR nYhrXTPpflukrpYbCoMN7vwMqlsRD4w06NFWO05PIJohmj5rlmeYADo++4zQ8lbuYXD4 t5J47a87tTB/x/fXm9WIktLi29UZpf8iyyoCETOp3xug4Ova6jrowi/oxa+xbeAzV9mq R8Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678418820; 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=fJCP5DpsUq8WkHYd2XyUpcCVaPjbDmPbS+iSJ8cOURA=; b=GaVS+R6jVFYOw34WOUjcBge6tgrKIuvEvkGDgLAXFBqCOSiPtacdG/6ObF4PVfOKBe R2vpAS72aK131Fp9T5FLuVYRykVmwZXUqJQJtGKAU/zqiQuga+l/YlmBAzdKJKA6ETQD meN4lUtcrt6AwtndEmIf84IqK9eoFVlAWGtYMcu+PhZifbKk+L7MYqmCui+Tssb+3EKn RqtxmG/MsIw/I7g7cdij9wLXpkw3oZkaQqyb0zGfHm4XY0LkfQqTDfvo0RRH4FjKLqp1 hEOwkZIaY8+iJ8nZrUnBk2TLn0jKGNAP4TmrFphf2ERtzVI+gGf3o/pARoOHyhIPb8vf Su+A== X-Gm-Message-State: AO0yUKVIajvnZpZmoTHNW6+7WvliTO/nd2EELgzcxA5el3P0r/w/S2jm rAGVhBcxaY4YyJUltLLRN27JYcbIU2xu7yyQIK686wQDSHQ= X-Google-Smtp-Source: AK7set9qO/u8Yc7w/2OPKIWP+zg1UQ+EGfX0LiLfFnw7y1UFfyzhDYJTkqp8OQpPG5TAXabpd2D7DTGxKfIv+aelCBA= X-Received: by 2002:a4a:9e81:0:b0:524:f77c:5443 with SMTP id u1-20020a4a9e81000000b00524f77c5443mr346120ook.1.1678418820095; Thu, 09 Mar 2023 19:27:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Fri, 10 Mar 2023 12:26:23 +0900 Message-ID: Subject: Re: Should vacuum process config file reload more often To: Melanie Plageman Cc: Pg Hackers , Andres Freund , Amit Kapila 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 Fri, Mar 10, 2023 at 11:23=E2=80=AFAM Melanie Plageman wrote: > > On Tue, Mar 7, 2023 at 12:10=E2=80=AFAM Masahiko Sawada wrote: > > > > On Mon, Mar 6, 2023 at 5:26=E2=80=AFAM Melanie Plageman > > wrote: > > > > > > On Thu, Mar 2, 2023 at 6:37=E2=80=AFPM Melanie Plageman > > > In this version I've removed wi_cost_delay from WorkerInfoData. There= is > > > no synchronization of cost_delay amongst workers, so there is no reas= on > > > to keep it in shared memory. > > > > > > One consequence of not updating VacuumCostDelay from wi_cost_delay is > > > that we have to have a way to keep track of whether or not autovacuum > > > table options are in use. > > > > > > This patch does this in a cringeworthy way. I added two global > > > variables, one to track whether or not cost delay table options are i= n > > > use and the other to store the value of the table option cost delay. = I > > > didn't want to use a single variable with a special value to indicate > > > that table option cost delay is in use because > > > autovacuum_vacuum_cost_delay already has special values that mean > > > certain things. My code needs a better solution. > > > > While it's true that wi_cost_delay doesn't need to be shared, it seems > > to make the logic somewhat complex. We need to handle cost_delay in a > > different way from other vacuum-related parameters and we need to make > > sure av[_use]_table_option_cost_delay are set properly. Removing > > wi_cost_delay from WorkerInfoData saves 8 bytes shared memory per > > autovacuum worker but it might be worth considering to keep > > wi_cost_delay for simplicity. > > Ah, it turns out we can't really remove wi_cost_delay from WorkerInfo > anyway because the launcher doesn't know anything about table options > and so the workers have to keep an updated wi_cost_delay that the > launcher or other autovac workers who are not vacuuming that table can > read from when calculating the new limit in autovac_balance_cost(). IIUC if any of the cost delay parameters has been set individually, the autovacuum worker is excluded from the balance algorithm. > > However, wi_cost_delay is a double, so if we start updating it on config > reload in vacuum_delay_point(), we definitely need some protection > against torn reads. > > The table options can only change when workers start vacuuming a new > table, so maybe there is some way to use this to solve this problem? > > > > It is worth mentioning that I think that in master, > > > AutoVacuumUpdateDelay() was incorrectly reading wi_cost_limit and > > > wi_cost_delay from shared memory without holding a lock. > > > > Indeed. > > > > > I've added in a shared lock for reading from wi_cost_limit in this > > > patch. However, AutoVacuumUpdateLimit() is called unconditionally in > > > vacuum_delay_point(), which is called quite often (per block-ish), so= I > > > was trying to think if there is a way we could avoid having to check > > > this shared memory variable on every call to vacuum_delay_point(). > > > Rebalances shouldn't happen very often (done by the launcher when a n= ew > > > worker is launched and by workers between vacuuming tables). Maybe we > > > can read from it less frequently? > > > > Yeah, acquiring the lwlock for every call to vacuum_delay_point() > > seems to be harmful. One idea would be to have one sig_atomic_t > > variable in WorkerInfoData and autovac_balance_cost() set it to true > > after rebalancing the worker's cost-limit. The worker can check it > > without locking and update its delay parameters if the flag is true. > > Maybe we can do something like this with the table options values? Since an autovacuum that uses any of table option cost delay parameters is excluded from the balancing algorithm, the launcher doesn't need to notify such workers of changes of the cost-limit, no? Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com