Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLFJk-002eqZ-Dk for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jul 2023 03:54:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qLFJh-004D8B-Nu for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jul 2023 03:54:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLFJh-004D83-Et for pgsql-hackers@lists.postgresql.org; Mon, 17 Jul 2023 03:54:33 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qLFJc-000z1m-Q2 for pgsql-hackers@lists.postgresql.org; Mon, 17 Jul 2023 03:54:32 +0000 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7835e5fa459so159732439f.2 for ; Sun, 16 Jul 2023 20:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689566067; x=1692158067; 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=Gupn4w+XDntyYOeE+qwWAb9z2LtQ5vV43p5LvQyedcc=; b=RXh1pwgxDETam9GyQyUEHvcbgVSsKyUqTkeuJi3oLAZx/RFLD5VYLbg3Q28qDOA7rf wmO7xspa7dseiW49VXPjKOg6/sKtYHqqPJj2En1TWnk1ouo7j2rBGTC5/H1+008UtKwH 62Ctd5ait2xOu+LAlNBmBrHW8DQzzYAqplQkcgU10O1inrjsJT21IMUB0KCV2qZge2r0 3LGBhadlVCNGL/WVCvNps1fV2GfNJ2hQlL8hzxD4rnRzgMosVOgTZHSyAqp13UAeLHZC JoWa5dUUkuyw4jAbkIQR4Qfgp9tc6ZzXL3nMeFR0OvBVbTLDy2zjPlJr5aHj/9+6nOfQ fk+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689566067; x=1692158067; 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=Gupn4w+XDntyYOeE+qwWAb9z2LtQ5vV43p5LvQyedcc=; b=Ggl5zzfColY3XbbMRAEVyYx2BivHFG7easytKakzUrt+UeazpAFmsoak7Z+X5hj3Zh j0F0XyQ73c4DHlD3iULH6JUpVelM/7heol3zWA5w/K2HKwvIWSVs2QXc+2yqeosMlng/ WOTMOMb+Z4PaOdaCjvDWttOjk72BN51gq8f4T5EbnKKIME+T9baMcFTemp72AEkh5SS7 LKKikQM2SW9B/OTSw7yMsh04uniJ0/K/TBYtQq2scOJOPIHygokdtr2wo2b0nwQBVkQ6 hu5sTLrE40+3WvgPmv//nk9tjwXXAdbcG9vclezUZB48v08O9X6JjoUrQm06fmXi2BJl IUBg== X-Gm-Message-State: ABy/qLa2Gu6br8ZiBLsIxXjUxpeHLw+1vXryG++geIBDhYbJk04r6Ztv cfkrRk7o+8kW82QE3scFTcwD/lzI280= X-Google-Smtp-Source: APBJJlH+CrXCfWmL0sNrarjuHUVxbockjbFAooLHZ7o40q+or80xfbZEu2TQsF84Rj5tMcwh41A/nQ== X-Received: by 2002:a92:c011:0:b0:345:6e49:30d2 with SMTP id q17-20020a92c011000000b003456e4930d2mr9745971ild.10.1689566066619; Sun, 16 Jul 2023 20:54:26 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id z16-20020a17090a609000b00263d7c5323dsm4494292pji.49.2023.07.16.20.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jul 2023 20:54:26 -0700 (PDT) Date: Sun, 16 Jul 2023 20:54:24 -0700 From: Nathan Bossart To: Tom Lane Cc: Andrew Dunstan , pgsql-hackers@lists.postgresql.org Subject: Re: Inefficiency in parallel pg_restore with many tables Message-ID: <20230717035424.GA541888@nathanxps13> References: <3612876.1689443232@sss.pgh.pa.us> <3787685.1689515154@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3787685.1689515154@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Jul 16, 2023 at 09:45:54AM -0400, Tom Lane wrote: > Actually, as long as we're talking about approximately-correct behavior: > let's make the ready_list be a priority heap, and then just make > pop_next_work_item scan forward from the array start until it finds an > item that's runnable per the lock heuristic. If the heap root is > blocked, the next things we'll examine will be its two children. > We might pick the lower-priority of those two, but it's still known to > be higher priority than at least 50% of the remaining heap entries, so > it shouldn't be too awful as a choice. The argument gets weaker the > further you go into the heap, but we're not expecting that having most > of the top entries blocked will be a common case. (Besides which, the > priorities are pretty crude to begin with.) Once selected, pulling out > an entry that is not the heap root is no problem: you just start the > sift-down process from there. > > The main advantage of this over the only-sort-sometimes idea is that > we can guarantee that the largest ready item will always be dispatched > as soon as it can be (because it will be the heap root). So cases > involving one big table (with big indexes) and a lot of little ones > should get scheduled sanely, which is the main thing we want this > algorithm to ensure. With the other approach we can't really promise > much at all. This seems worth a try. IIUC you are suggesting making binaryheap.c frontend-friendly and expanding its API a bit. If no one has volunteered, I could probably hack something together. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com