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 1paSPb-0001Z8-5d for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Mar 2023 02:23:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1paSPZ-0007w7-T7 for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Mar 2023 02:23:13 +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 1paSPZ-0007vy-Br for pgsql-hackers@lists.postgresql.org; Fri, 10 Mar 2023 02:23:13 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1paSPS-0004Hq-9j for pgsql-hackers@postgresql.org; Fri, 10 Mar 2023 02:23:12 +0000 Received: by mail-pf1-x42e.google.com with SMTP id x7so2765500pff.7 for ; Thu, 09 Mar 2023 18:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678414985; 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=mdppWi5Mo/aH/SjqGqhWCGYjPiTyQ1toDGs6/sHTDQQ=; b=UPl+7JV18fz5Rs8swKWkL0NcF1AxqKG/1YiRfXduKFc7OH06Org8kF3zvQ1U9bNZGI R1+2uBGee/GJycroS56ay5z1PKoaMcOOtVnEmayMknU5D7aypWfHNwHXQEItGRKPCAv5 LeavIYmTtKt2rLYVo4Q2qXpnzeuXMO8Z/Mac3FSzP7ejIdtYqgsU2i22/djrW+ZLP7S2 EVO5dgtnr9U8S7UdVkvRDnVApIRt2a2keBAV4T1HwD6FNnYY3M/4kLaipvuTMB9SFVuu e/+5pywYauJAwP/izZ5FrtPDDPk4WsYLeDcujt4CWfMP+mfs8kx/Q/f6TtpHcTyKpQuE aCeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678414985; 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=mdppWi5Mo/aH/SjqGqhWCGYjPiTyQ1toDGs6/sHTDQQ=; b=VuAKUnXcD5rsbHU3zfWg1ziYld0Fsr5bE6bsVMZM22OODRZmTlOGIL1TTrB/Entoxv +U07YZevamYQh84Pf51zORLbfPrwMwB3Yy/IniAICuhe4WwQ8M9IFrAbSwy6tip4gSBb bl/y8gpoj31c5rzekcsGTjzYEP6d6gxnqge2Nr6tE0iLUVhntJmrGS3sulDuJxcKC/Qh Xg6aiQuydLSeCTE67mu67hDL84w11ad0ga78vSBJHsD7PKmg1/fPJPknkaJPDrNGu/6P liX5Q7frd4fA8MYHP16oNnSeDgoK+d/Tz8NOu/U5KI/JUTLRr+AbjP+dTN3ezMoG7aGC wmpg== X-Gm-Message-State: AO0yUKUaaDHt7Exu3nyc67NfeOs/LSLlZzJs25w2LPJJ0gasKP38397O IjFN6CweGruDCqx7WtkY4sEpS9TbhbXI0G9ZeBs= X-Google-Smtp-Source: AK7set/DFl/iwTZSv2mPkDSouyE9dYCSfh37yfYcY/1gjGiO/uvmdb/JXRwCWpzkeANpIFrwURAKxakNM9BPinBAaHo= X-Received: by 2002:a65:6213:0:b0:4fd:72f3:5859 with SMTP id d19-20020a656213000000b004fd72f35859mr264131pgv.2.1678414985001; Thu, 09 Mar 2023 18:23:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Melanie Plageman Date: Thu, 9 Mar 2023 21:22:53 -0500 Message-ID: Subject: Re: Should vacuum process config file reload more often To: Masahiko Sawada 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 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 i= s > > no synchronization of cost_delay amongst workers, so there is no reason > > 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 in > > 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(). 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 new > > 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? - Melanie