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 1pj5Iy-0008FG-B3 for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Apr 2023 21:32:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pj5Iw-0001D1-S6 for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Apr 2023 21:32:02 +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 1pj5Iw-0001AW-GH for pgsql-hackers@lists.postgresql.org; Sun, 02 Apr 2023 21:32:02 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pj5Ir-000Vzj-A5 for pgsql-hackers@postgresql.org; Sun, 02 Apr 2023 21:32:01 +0000 Received: by mail-pl1-x62e.google.com with SMTP id kc4so26196321plb.10 for ; Sun, 02 Apr 2023 14:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680471115; 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=zXyU9m2FQJnYMEa7dQNxI1ars90kEXv8jWlobOXlkho=; b=eXhx10yRi4rVtO3MlwNUsYyP6SSCCFOGKMoflPnJNm0IltVxZohe/hyKZnlyEm0NXK XfX/cajY6/adjgHymKN/Am/1qqCV9APpmvZ6PPTyYA8jWFrN6stVvJDVplhwazYxPS+0 me/RvHmV+XgtStJzH6T+JtQRpxktsIhDdsllBnXUKfJvftaXLDtjI8Vp5xLokWBpYy3s 4eZjVMTzEXvXmiZwoVA2+Nu2bsjyZ1+jCxi04cETbXnUi+WcZ+1PSAAdpeG12bPKr0Po XGyjZ4kgUiWCFPI1OJg8wCII9rxolgasIqhuqPXbUrWPkBAvmCnlzjPzAUqYUD7uzYbx UsMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680471115; 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=zXyU9m2FQJnYMEa7dQNxI1ars90kEXv8jWlobOXlkho=; b=I2FgIfeIRqwd1H0g1Mf+OKOMADw8igsfH6gXFnbXwLCQ9fd4Xgn7FC0l0Sp5OVr/q3 EvGHfbosBL04uR4O0TxI6FObdFn07xPQdHRn4h6mDfXY0whJ1WmoXOLfF8PqDtIIk6+D YCWJyYPUs2Bl1KSmJ3XbgJN396evImxtfKivjtYYa+qKYFW9YVkYVi1Uq/oIPPdCYG85 2GxHmQDftoz++IZd/Szs9oxU/xNQs6kdMYL40pnccmPg8cdyVFkvTrIO8TBKgz4+rM2U IsiMfTPzLfS3BHNBaDB9jr/JlaJvCDlQHQbBH1BgvypRUnOEZRelbZiP+QK5nu+Tvdnm N0AQ== X-Gm-Message-State: AAQBX9cGP/3NODl+v6FqjUUq22Uu1pd40bmryJOE/ndRVtbrPNEbTxJz Zz0OLY35USdHSTyYnnoMQnI= X-Google-Smtp-Source: AKy350YiA1GbiOKvtlIbAy7qk6MRYdVrnTtW64c6m+eW8iPXRZe//4BT6mbvwdUGdY1TGMjY0XpHaw== X-Received: by 2002:a17:902:f9cf:b0:1a0:7508:dae6 with SMTP id kz15-20020a170902f9cf00b001a07508dae6mr28870691plb.63.1680471115195; Sun, 02 Apr 2023 14:31:55 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id bd10-20020a170902830a00b001991f3d85acsm5138070plb.299.2023.04.02.14.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 14:31:54 -0700 (PDT) Date: Sun, 2 Apr 2023 14:31:52 -0700 From: Nathan Bossart To: Tom Lane Cc: Andres Freund , Bharath Rupireddy , Robert Haas , "Bossart, Nathan" , Maxim Orlov , Amul Sul , Bruce Momjian , "pgsql-hackers@postgresql.org" Subject: Re: O(n) tasks cause lengthy startups and checkpoints Message-ID: <20230402213152.GB27239@nathanxps13> References: <20221201214026.GA1799688@nathanxps13> <20221202191507.GA2277157@nathanxps13> <20230203054808.GA83788@nathanxps13> <20230217234344.GA3357392@nathanxps13> <1031491.1680457205@sss.pgh.pa.us> <20230402184226.kkjplqvqu6utvzbt@awork3.anarazel.de> <20230402195005.GB25018@nathanxps13> <1058306.1680467858@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1058306.1680467858@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Apr 02, 2023 at 04:37:38PM -0400, Tom Lane wrote: > Nathan Bossart writes: >> It's been a little while since I dug into this, but I do see your point >> that the wraparound risk could be higher in some cases. For example, if >> you have a billion temp files to clean up, the custodian could be stuck on >> that task for a long time. I will give this some further thought. I'm all >> ears if anyone has ideas about how to reduce this risk. > > I wonder if a single long-lived custodian task is the right model at all. > At least for RemovePgTempFiles, it'd make more sense to write it as a > background worker that spawns, does its work, and then exits, > independently of anything else. Of course, then you need some mechanism > for ensuring that a bgworker slot is available when needed, but that > doesn't seem horridly difficult --- we could have a few "reserved > bgworker" slots, perhaps. An idle bgworker slot doesn't cost much. This has crossed my mind. Even if we use the custodian for several different tasks, perhaps it could shut down while not in use. For many servers, the custodian process will be used sparingly, if at all. And if we introduce something like custodian_max_workers, perhaps we could dodge the wraparound issue a bit by setting the default to the number of supported tasks. That being said, this approach adds some complexity. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com