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 1mt93g-0002pv-6l for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Dec 2021 13:57: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 1mt93f-0004V1-4M for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Dec 2021 13:57:03 +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 1mt93e-0004Us-R3 for pgsql-hackers@lists.postgresql.org; Fri, 03 Dec 2021 13:57:02 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mt93b-0001Rk-K9 for pgsql-hackers@postgresql.org; Fri, 03 Dec 2021 13:57:02 +0000 Received: by mail-pj1-x102f.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so5219541pju.3 for ; Fri, 03 Dec 2021 05:56:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2gS7Odhl2gEEWIdH+KwDhgF5yxKPRFfX9ulNzWiyUMM=; b=H6mjDDc5E/W19kY5TlB0wRh3NJh2LWJgO1Ek6olpAb+iq8w9KsCBeh1KYdX+ObZHDf 4CGySyaqiXRPYioRA7mmnjTvQzWBH3j52RDwfzThg9OcENlrdXFaz3bpIiPbI6g00sWh jV+scYeAEy+yGnjRI27lbdyB9bsznKb96nKNekZvptuEkQ+SwCUNjCgleih4DZ45UvP6 Si6fIZi9K3Eh5jATGnAr1ALztce9oqevXukYkXepbJ2j2IbGUfHv9nrJ72QmCzFQ0scU ltFfSb9tEregDesD6Xio7l2n6r01CrCROjDi814D3LCzfL8EGXGFFQiquzMXPQUINH5g 666A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2gS7Odhl2gEEWIdH+KwDhgF5yxKPRFfX9ulNzWiyUMM=; b=xTvjyHuTFSNNVCnP16wJjQMatmVyCRE4tTTDPFbilax40yjUbazHwOPV28+RhObe5d msMDdJWzc+LvgGHUtvsbqPoNkCxBM9JL/s/mJWE595tPlV5PrrMbxe8lQKNuA7TmwhEu SfYgSu71COfONTkXtuoxVIXh1BS1/LqxsnyHwLjOXzm89RJNwzxK4jLnkwiZIF+zkp2Y DzejjiZUHrwM6oU+HOpjFhcDiueTgskzFuWMJIahCin9UxYUZTWrKsiygdxFMz8JNNRW IHSEyWQhxsobhDZjkZG4TdefNwLi5lyBQvnoIvyEOgmu5Zqe4xK1ULTIF4xbDhoh/NWu f2TA== X-Gm-Message-State: AOAM5310J8FGvUKfxmwDpRjRcJc7GU0as7LaapNWSP1RhODaNXiFuA2v aT/kgAGV9Z2ysUnGLRsf0cZt023ScruBhrJUJEU= X-Google-Smtp-Source: ABdhPJznkcX8X207bvsp/kL1tm1SvOLA9QPRlFArHUwtit1GuMKYUG1vfy5NeiqUSsPk6AZ79Q8iAiex/1reSYibRxo= X-Received: by 2002:a17:902:c713:b0:141:bbb2:1ec7 with SMTP id p19-20020a170902c71300b00141bbb21ec7mr22829109plp.57.1638539817465; Fri, 03 Dec 2021 05:56:57 -0800 (PST) MIME-Version: 1.0 References: <5E58EBB2-3DAE-4400-9EBE-60D1FE4C5B10@amazon.com> In-Reply-To: <5E58EBB2-3DAE-4400-9EBE-60D1FE4C5B10@amazon.com> From: Bharath Rupireddy Date: Fri, 3 Dec 2021 19:26:46 +0530 Message-ID: Subject: Re: O(n) tasks cause lengthy startups and checkpoints To: "Bossart, Nathan" Cc: "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Dec 3, 2021 at 3:01 AM Bossart, Nathan wrote: > > On 12/1/21, 6:48 PM, "Bharath Rupireddy" wrote: > > +1 for the overall idea of making the checkpoint faster. In fact, we > > here at our team have been thinking about this problem for a while. If > > there are a lot of files that checkpoint has to loop over and remove, > > IMO, that task can be delegated to someone else (maybe a background > > worker called background cleaner or bg cleaner, of course, we can have > > a GUC to enable or disable it). The checkpoint can just write some > > Right. IMO it isn't optimal to have critical things like startup and > checkpointing depend on somewhat-unrelated tasks. I understand the > desire to avoid adding additional processes, and maybe it is a bigger > hammer than what is necessary to reduce the impact, but it seemed like > a natural solution for this problem. That being said, I'm all for > exploring other ways to handle this. Having a generic background cleaner process (controllable via a few GUCs), which can delete a bunch of files (snapshot, mapping, old WAL, temp files etc.) or some other task on behalf of the checkpointer, seems to be the easiest solution. I'm too open for other ideas. > > Another idea could be to parallelize the checkpoint i.e. IIUC, the > > tasks that checkpoint do in CheckPointGuts are independent and if we > > have some counters like (how many snapshot/mapping files that the > > server generated) > > Could you elaborate on this? Is your idea that the checkpointer would > create worker processes like autovacuum does? Yes, I was thinking that the checkpointer creates one or more dynamic background workers (we can assume one background worker for now) to delete the files. If a threshold of files crosses (snapshot files count is more than this threshold), the new worker gets spawned which would then enumerate the files and delete the unneeded ones, the checkpointer can proceed with the other tasks and finish the checkpointing. Having said this, I prefer the background cleaner approach over the dynamic background worker. The advantage with the background cleaner being that it can do other tasks (like other kinds of file deletion). Another idea could be that, use the existing background writer to do the file deletion while the checkpoint is happening. But again, this might cause problems because the bg writer flushing dirty buffers will get delayed. Regards, Bharath Rupireddy.