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 1piP6r-0001gL-26 for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Apr 2023 00:28:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1piP6p-0005ui-Tp for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Apr 2023 00:28:43 +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 1piP6p-0005uZ-EH for pgsql-hackers@lists.postgresql.org; Sat, 01 Apr 2023 00:28:43 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1piP6i-0006Bi-9z for pgsql-hackers@postgresql.org; Sat, 01 Apr 2023 00:28:42 +0000 Received: by mail-il1-x133.google.com with SMTP id o12so7367869ilh.13 for ; Fri, 31 Mar 2023 17:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; t=1680308915; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=SX1o9kaxqPit5FulowgUjy6jyFpkUC6Lc0a+9OBOxgM=; b=0hTUU4plI/aHu3k8sOEAwimbVkID50htRp1ZdnWKMBXHo4Erxc+3gSNPBCQeDuHyvP bAduGwyPEJKQ4WSXnvSuHnSChmGdVPzEv44HyLKjedv8czhs24PstjEDsqVIJ0Y3nu0R Z6a1RvmEv1QObVBC1vRzZwoTcND5sfAwdcvYz0URjD/G6BBIuBBeez791JCm6y6/ZzK+ uRW3lrkUZ2uTB/wdQoeW0kYM0rvViquQu7aBLVr1cC+Ic/qPjzUqznlt/mGoEUF61jP6 /TaqdLdCTYSjACS8Jsaezj8dmo98o77iasP5nJ/lgDmhnaMYsT2yqGx4E5vP1vqi03s+ MxOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680308915; h=in-reply-to:content-transfer-encoding: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=SX1o9kaxqPit5FulowgUjy6jyFpkUC6Lc0a+9OBOxgM=; b=lHKob4ayslD7BvI7bc/6tBvs+KxZBwSc5OuZH39AJt70sekecXpi56ID1HOdvooFgr L3il40RwS1sw0EnphVjbWL9vKI02jJp/sDFL5IaakhYoEC0xHc7ZZfzj5UQ7KdCp12s8 PJ+iWEOUcYnJOlQRODRsthL2aNzYlHp0vBgPNZ0HkXLUraAp/q3Kou/u6Y0yJpV5xuu0 ou4ihXuCkdvBRc6oz4b8Oa3K4G9t9kYZ0CpL2nUUwTTaKTB6bfe1yiCzY6hTr17KvDJ/ RupYk3RKulQKit7LaDUDK9miNUHIdKhzdvqgdz80+7zaXpODVLmzjMA5MUHD/FMC3i9b fUbA== X-Gm-Message-State: AAQBX9cvyqN7VchHVTfWkDoNoFkcTrG0fE9NZ5TPHPUKyq16hr3NNkeu jz2sFXIRHliUNjewfvWvXNSAow== X-Google-Smtp-Source: AKy350Y0pt9/xpTAWv40j+Wg/z+Sbaa3vQxMZTxIo6fm3n9hAmtIlbuK9d3I0x+7TR2K3o5nbgzB2g== X-Received: by 2002:a05:6e02:78d:b0:326:4568:2d30 with SMTP id q13-20020a056e02078d00b0032645682d30mr3439181ils.8.1680308915521; Fri, 31 Mar 2023 17:28:35 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id f10-20020a02a04a000000b003a958069dbfsm991349jah.8.2023.03.31.17.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 17:28:35 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 19F768007F5; Fri, 31 Mar 2023 19:28:34 -0500 (CDT) Date: Fri, 31 Mar 2023 19:28:33 -0500 From: Justin Pryzby To: Tomas Vondra Cc: Jacob Champion , pgsql-hackers@postgresql.org, gkokolatos@pm.me, Michael Paquier , Robert Haas , Peter Geoghegan , Peter Eisentraut , Heikki Linnakangas , Thomas Munro , Dipesh Pandit , Andrey Borodin , Mark Dilger Subject: Re: zstd compression for pg_dump Message-ID: References: <20230304165747.GH12850@telsasoft.com> <3d04afca-7d9d-c90f-5fef-5cf4fdb2173f@timescale.com> <0115b682-58f0-ea43-9ecd-c37a4495812e@enterprisedb.com> <0022dd9e-a439-d72f-d09b-ec512c23949b@enterprisedb.com> <4029fe58-f661-7d8d-cbbb-b936a05531e2@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4029fe58-f661-7d8d-cbbb-b936a05531e2@enterprisedb.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Apr 01, 2023 at 02:11:12AM +0200, Tomas Vondra wrote: > On 4/1/23 01:16, Justin Pryzby wrote: > > On Tue, Mar 28, 2023 at 06:23:26PM +0200, Tomas Vondra wrote: > >> On 3/27/23 19:28, Justin Pryzby wrote: > >>> On Fri, Mar 17, 2023 at 03:43:31AM +0100, Tomas Vondra wrote: > >>>> On 3/16/23 05:50, Justin Pryzby wrote: > >>>>> On Fri, Mar 10, 2023 at 12:48:13PM -0800, Jacob Champion wrote: > >>>>>> On Wed, Mar 8, 2023 at 10:59 AM Jacob Champion wrote: > >>>>>>> I did some smoke testing against zstd's GitHub release on Windows. To > >>>>>>> build against it, I had to construct an import library, and put that > >>>>>>> and the DLL into the `lib` folder expected by the MSVC scripts... > >>>>>>> which makes me wonder if I've chosen a harder way than necessary? > >>>>>> > >>>>>> It looks like pg_dump's meson.build is missing dependencies on zstd > >>>>>> (meson couldn't find the headers in the subproject without them). > >>>>> > >>>>> I saw that this was added for LZ4, but I hadn't added it for zstd since > >>>>> I didn't run into an issue without it. Could you check that what I've > >>>>> added works for your case ? > >>>>> > >>>>>>> Parallel zstd dumps seem to work as expected, in that the resulting > >>>>>>> pg_restore output is identical to uncompressed dumps and nothing > >>>>>>> explodes. I haven't inspected the threading implementation for safety > >>>>>>> yet, as you mentioned. > >>>>>> > >>>>>> Hm. Best I can tell, the CloneArchive() machinery is supposed to be > >>>>>> handling safety for this, by isolating each thread's state. I don't feel > >>>>>> comfortable pronouncing this new addition safe or not, because I'm not > >>>>>> sure I understand what the comments in the format-specific _Clone() > >>>>>> callbacks are saying yet. > >>>>> > >>>>> My line of reasoning for unix is that pg_dump forks before any calls to > >>>>> zstd. Nothing zstd does ought to affect the pg_dump layer. But that > >>>>> doesn't apply to pg_dump under windows. This is an opened question. If > >>>>> there's no solid answer, I could disable/ignore the option (maybe only > >>>>> under windows). > >>>> > >>>> I may be missing something, but why would the patch affect this? Why > >>>> would it even affect safety of the parallel dump? And I don't see any > >>>> changes to the clone stuff ... > >>> > >>> zstd supports using threads during compression, with -Z zstd:workers=N. > >>> When unix forks, the child processes can't do anything to mess up the > >>> state of the parent processes. > >>> > >>> But windows pg_dump uses threads instead of forking, so it seems > >>> possible that the pg_dump -j threads that then spawn zstd threads could > >>> "leak threads" and break the main thread. I suspect there's no issue, > >>> but we still ought to verify that before declaring it safe. > >> > >> OK. I don't have access to a Windows machine so I can't test that. Is it > >> possible to disable the zstd threading, until we figure this out? > > > > I think that's what's best. I made it issue a warning if "workers" was > > specified. It could also be an error, or just ignored. > > > > I considered disabling workers only for windows, but realized that I > > haven't tested with threads myself - my local zstd package is compiled > > without threading, and I remember having some issue recompiling it with > > threading. Jacob's recipe for using meson wraps works well, but it > > still seems better to leave it as a future feature. I used that recipe > > to enabled zstd with threading on CI (except for linux/autoconf). > > +1 to disable this if we're unsure it works correctly. I agree it's > better to just error out if workers are requested - I rather dislike > when a tool just ignores an explicit parameter. And AFAICS it's what > zstd does too, when someone requests workers on incompatible build. > > FWIW I've been thinking about this a bit more and I don't quite see why > would the threading cause issues (except for Windows). I forgot > pg_basebackup already supports zstd, including the worker threading, so > why would it work there and not in pg_dump? Sure, pg_basebackup is not > parallel, but with separate pg_dump processes that shouldn't be an issue > (although I'm not sure when zstd creates threads). There's no concern at all except under windows (because on windows pg_dump -j is implemented using threads rather than forking). Especially since zstd:workers is already allowed in the basebackup backend process. > I'll try building zstd with threading enabled, and do some tests over > the weekend. Feel free to wait until v17 :) I used "meson wraps" to get a local version with threading. Note that if you want to use a zstd subproject, you may have to specify -D zstd=enabled, or else meson may not enable the library at all. Also, in order to introspect its settings, I had to do like this: mkdir subprojects meson wrap install zstd meson subprojects download mkdir build.meson meson setup -C build.meson --force-fallback-for=zstd -- Justin