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 1pN0d0-0000NU-Hq for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 00:05:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pN0cz-00045U-5N for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 00:05:29 +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 1pN0cy-00045B-Ps for pgsql-hackers@lists.postgresql.org; Wed, 01 Feb 2023 00:05:28 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pN0cw-0004he-AI for pgsql-hackers@postgresql.org; Wed, 01 Feb 2023 00:05:28 +0000 Received: by mail-pg1-x532.google.com with SMTP id f3so11292962pgc.2 for ; Tue, 31 Jan 2023 16:05:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=SetkxwqKCxcfTsaO0uSLlGRDlPjzdBOnRhgwri+pPE8=; b=bywEqf+bqtKRxZZMrNCSJe/jqwtP87A9r0U3GS8b0iE3TJBtFV4AxHBaWVqb7knMNM Pco7zb7jVf/zJ6ArdnWW94FrHcRLDAsRleb22KBXD/JZ722w3HbdvFl2qcatLw4JimIS QmDZhvbYC4Nxuf2OvT4XCSOGiELoh8kmKzXi4S6vbrr5+lPT7pCvp4/Is8CLcRv4qjep aWpIo0r+DUQZDonrWqiknZOO30WulYf5hpJBkcbTS5iLrxj5zLs/YOvp5w1AOH2oFijn uR4WHeEBSx/Ia6ojB28ucU3LNlz4SNMFzTACYg5CLI0LzwHZFlhfIYi4qD12+ofLz3TM MqFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SetkxwqKCxcfTsaO0uSLlGRDlPjzdBOnRhgwri+pPE8=; b=IEaOzBqhvboqPD3CjrTIq9MnShV8gVF1YEA/2yzEsZfVvC3v5DOF1N6/+5FoUy/RQg wK7RBP0iQd92YoMMSEcqpDG/x2XXYWDEez5zOs0F4Ys0wyMelCPsl21IILOWcdcLsfa7 O/uWSXGI9hCn1/FkxFznd1ciJjx5VE2xukwprmo4pXL5BJUhCIgwhRfatOtjYm2Oc79H nKttgeCrZB5Qa6BsP4eZdXICNgafSPs8+ejdcHCN5ZsoXQX5oQ2UtgUhrKjA4wZJ8p3r 766pCxMpXXiC87xlXStvELqe74v0bsX8yownrgh8u1o6BcorVvGOere2EqEjOSbpm1Up LsDQ== X-Gm-Message-State: AO0yUKVXPrXEIDHIHn0BuGB7Uva7Es45jVVyTBxyn4qqJQjDKe25f70C K0QueN/I2UHZRMwbOYVRfFo= X-Google-Smtp-Source: AK7set9LTdo9yHwUTf0ECyu03Ly4yNA86JJcZNyY3ZQ0RwKG5kEhqXTTHuEeBQan4afoowplrw3Kyw== X-Received: by 2002:a05:6a00:b47:b0:58d:988b:da99 with SMTP id p7-20020a056a000b4700b0058d988bda99mr455227pfo.19.1675209924059; Tue, 31 Jan 2023 16:05:24 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id k5-20020aa79985000000b0059398b45272sm6739640pfh.58.2023.01.31.16.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 16:05:23 -0800 (PST) Date: Tue, 31 Jan 2023 16:05:21 -0800 From: Nathan Bossart To: Amit Kapila Cc: Tom Lane , Thomas Munro , "Hayato Kuroda (Fujitsu)" , "pgsql-hackers@postgresql.org" Subject: Re: suppressing useless wakeups in logical/worker.c Message-ID: <20230201000521.GA3147405@nathanxps13> References: <2888102.1674705840@sss.pgh.pa.us> <3126727.1674759248@sss.pgh.pa.us> <20230126194812.GA1702315@nathanxps13> <3165443.1674763470@sss.pgh.pa.us> <20230126202301.GA1703463@nathanxps13> <3211341.1674767391@sss.pgh.pa.us> <20230126212255.GA1746118@nathanxps13> <3220831.1674772625@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Jan 28, 2023 at 10:26:25AM +0530, Amit Kapila wrote: > On Fri, Jan 27, 2023 at 4:07 AM Tom Lane wrote: >> Returning to the prior patch ... I don't much care for this: >> >> + /* Maybe there will be a free slot in a second... */ >> + retry_time = TimestampTzPlusSeconds(now, 1); >> + LogRepWorkerUpdateSyncStartWakeup(retry_time); >> >> We're not moving the goalposts very far on unnecessary wakeups if >> we have to do that. Do we need to get a wakeup on sync slot free? >> Although having to send that to every worker seems ugly. Maybe this >> is being done in the wrong place and we need to find a way to get >> the launcher to handle it. It might be feasible to set up a before_shmem_exit() callback that wakes up the apply worker (like is already done for the launcher). I think the apply worker is ordinarily notified via the tablesync worker's notify_pid, but AFAICT there's no guarantee that the apply worker hasn't restarted with a different PID. > + /* > + * Since process_syncing_tables() is called conditionally, the > + * tablesync worker start wakeup time might be in the past, and we > + * can't know for sure when it will be updated again. Rather than > + * spinning in a tight loop in this case, bump this wakeup time by > + * a second. > + */ > + now = GetCurrentTimestamp(); > + if (wakeup[LRW_WAKEUP_SYNC_START] < now) > + wakeup[LRW_WAKEUP_SYNC_START] = > TimestampTzPlusSeconds(wakeup[LRW_WAKEUP_SYNC_START], 1); > > Do we see unnecessary wakeups without this, or delay in sync? I haven't looked too cloesly to see whether busy loops are likely in practice. > BTW, do we need to do something about wakeups in > wait_for_relation_state_change()? ... and wait_for_worker_state_change(), and copy_read_data(). From a quick glance, it looks like fixing these would be a more invasive change. TBH I'm beginning to wonder whether all this is really worth it to prevent waking up once per second. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com