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 1mnRdH-0006bS-F9 for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Nov 2021 20:34: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 1mnRdG-0006eE-Aq for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Nov 2021 20:34:14 +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 1mnRdF-0006e5-N8 for pgsql-hackers@lists.postgresql.org; Wed, 17 Nov 2021 20:34:13 +0000 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mnRd8-0006cl-Gi for pgsql-hackers@postgresql.org; Wed, 17 Nov 2021 20:34:12 +0000 Received: by mail-io1-xd36.google.com with SMTP id y16so4968052ioc.8 for ; Wed, 17 Nov 2021 12:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=bB10my4Z8uoA8+dihpVmRhkiwBLcHE+aokRK4GuLt00=; b=egA0Z6jlZt8Pkeovrln8u/t5PKt1tYKwZegv7w7gp7P6xj07GS5QyBsfSUub29yftd d75r9IoVTAGMin+J/qKW3tozEiBJo/DPb9nTZOlspgnjaExSz/26ArOw3tfNJAQUjiZZ KXgpygTz5nNv++hk2oms0JUQk6jZSG+7n7/2OsAx6UkVetQLQ+43ffkGO3cyMbbit/w/ +oZrLdbK29e2B4VBL3fNFBjd1DwUcsNdQUpSTiPHCTbLdCjk+YAIgP9U2A5XrBdk91Ek wtlSJvPGC/Aet9ecswVAATP4GPNhMtzbFcgbR24hqC1GMLiTxiSYJTbPgruJj0YfMJyj vkPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=bB10my4Z8uoA8+dihpVmRhkiwBLcHE+aokRK4GuLt00=; b=WX7B8lZgKNCFQX96uWv7DA+QQuG0er5YdN4ikLD22p/ex+m8xHb7zMFdB7STIuVvXC fgMjuw8ExcTqN4BcUugRvcTp0+xXmMq/M/gh/hViReEh8Zlmp1Kkxfoo/WzkA6bAK5LV DnwXQbtWyfpqbYkxV2uhscfKxBMx1D6zPHrQe3s+FRMtehId1rjZlGh4oVvWOJyAIAzY OuAOeXh/B/jCH0YeBDka6OYhpjPjHE1R5urTPdxgoGeTpszRjnuiDgXs7tC22eFufPOF bUKhWGt8dmG2YW3gx7yuoRfNvTrx13aL3Z/UjelTqlCF4rPzTWMiBKoOvS7xM/j7/zVQ 8D4Q== X-Gm-Message-State: AOAM531s33GdC49IQJmVsKGEbFiRizeH9LzuxVnncbEGaoJFX36c0nqG VF67i0czFu3A3Nm2psB2YoHLtaS75iK95A== X-Google-Smtp-Source: ABdhPJwXYdSQD+DZxdfHjnaYyLcFZkxzlhB9VVv7ElqRMY46OXaPcuv+JrkEOjNb0q8KMJfW7oyIpg== X-Received: by 2002:a05:6602:8da:: with SMTP id h26mr13192652ioz.76.1637181245390; Wed, 17 Nov 2021 12:34:05 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 1sm528803ill.57.2021.11.17.12.34.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Nov 2021 12:34:04 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id D65668009C6; Wed, 17 Nov 2021 14:34:03 -0600 (CST) Date: Wed, 17 Nov 2021 14:34:03 -0600 From: Justin Pryzby To: Jaime Casanova Cc: pgsql-hackers@postgresql.org Subject: Re: pg_upgrade parallelism Message-ID: <20211117203403.GE17618@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Nov 17, 2021 at 02:44:52PM -0500, Jaime Casanova wrote: > Hi, > > Currently docs about pg_upgrade says: > > """ > > The option allows multiple CPU cores to be used > for copying/linking of files and to dump and reload database schemas > in parallel; a good place to start is the maximum of the number of > CPU cores and tablespaces. This option can dramatically reduce the > time to upgrade a multi-database server running on a multiprocessor > machine. > > """ > > Which make the user think that the --jobs option could use all CPU > cores. Which is not true. Or that it has anything to do with multiple > databases, which is true only to some extent. > > What that option really improves are upgrading servers with multiple > tablespaces, of course if --link or --clone are used pg_upgrade is still > very fast but used with the --copy option is not what one could expect. > As an example, a customer with a 25Tb database, 40 cores and lots of ram > used --jobs=35 and got only 7 processes (they have 6 tablespaces) and > the disks where not used at maximum speed either. They expected 35 > processes copying lots of files at the same time. I would test this. How long does it take to cp -r the data dirs vs pg_upgrade them ? If running 7 "cp" in parallel is faster than the "copy" portion of pg_upgrade -j7, then pg_upgrade's file copy should be optimized. But if it's not faster, then maybe should look at other options, like your idea to copy filenodes (or their segments) in parallel. > So, first I would like to improve documentation. What about something > like the attached? The relevant history is in commits 6f1b9e4efd94fc644f5de5377829d42e48c3c758 a89c46f9bc314ed549245d888da09b8c5cace104 --jobs originally parallelized pg_dump and pg_restore, and then added copying/linking. So the docs should mention tablespaces, as you said, but should also mention databases. It may not be an issue for you, but pg_restore is the slowest part of our pg_upgrades, since we have many partitions. > Now, a couple of questions: > > - in src/bin/pg_upgrade/file.c at copyFile() we define a buffer to > determine the amount of bytes that should be used in read()/write() to > copy the relfilenode segments. And we define it as (50 * BLCKSZ), > which is 400Kb. Isn't this too small? Maybe - you'll have to check :) > - why we read()/write() at all? is not a faster way of copying the file? > i'm asking that because i don't actually know. No portable way. Linux has this: https://man7.org/linux/man-pages/man2/copy_file_range.2.html But I just read: | First support for cross-filesystem copies was introduced in Linux | 5.3. Older kernels will return -EXDEV when cross-filesystem | copies are attempted. To me that sounds like it may not be worth it, at least not quite yet. But it would be good to test. > I'm trying to add more parallelism by copying individual segments > of a relfilenode in different processes. Does anyone one see a big > problem in trying to do that? I'm asking because no one did it before, > that could not be a good sign. My concern would be if there's too many jobs and the storage bogs down, then it could be slower. I think something like that should have a separate option, not just --jobs. Like --parallel-in-tablespace. The original implementation puts processes across CPUs (for pg_dump/restore) and tablespaces (for I/O). Maybe it should be possible to control those with separate options, too. FWIW, we typically have only one database of any significance, but we do use tablespaces, and I've used pg_upgrade --link since c. v9.0. --jobs probably helps pg_dump/restore at few customers who have multiple DBs. But it probably doesn't help to parallelize --link across tablespaces (since our tablespaces are actually on the same storage devices, but with different filesystems). I anticipate it might even make a few customers upgrade a bit slower, since --link is a metadata operation and probably involves a lot of FS barriers, for which the storage may be inadequate to support in parallel. -- Justin