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 1nPWcD-0008Lk-9d for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Mar 2022 21:34:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nPWbg-0005zL-J7 for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Mar 2022 21:34:00 +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 1nPWbg-0005zB-9H for pgsql-hackers@lists.postgresql.org; Wed, 02 Mar 2022 21:34:00 +0000 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nPWbc-0006V6-Si for pgsql-hackers@lists.postgresql.org; Wed, 02 Mar 2022 21:33:59 +0000 Received: by mail-il1-x130.google.com with SMTP id i14so2500497ilv.4 for ; Wed, 02 Mar 2022 13:33:56 -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:content-transfer-encoding:in-reply-to :user-agent; bh=xoJl8aTlh9L4SCH5daGjPY3CAuwdjbn3W0lK0xi0Cko=; b=0upe8SCUkDeXsfEwuccUTMzbhftcjRqumjZsiA0N3T+BdYYKuKGcI/4SbpTTIjNw5w 7Uue+JmMFmBgiN319K1BkYceaeoguy4KcxQWAgIH2r/G2UqIhEzzXqEf0jr/SYy6Vn2W aMJVDTAecM+2/BrEvyQSXzqkrha1Bisj7nFCktH+nmBSBzKOcDTqfBylX23vAfr23IKT 5lA/Ip+uheOpdp3ybumF+SghPbB4JhppTOA3g5wK2BixB6Keyyxx13SC5ag7OzBshYQ5 9wpV1m2Wjs5TMMzrbB7bdBv346vXmSdofEop/ECNZLGhSY9FR4MgNIGTfji3FQcesi/N A4tw== 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:content-transfer-encoding :in-reply-to:user-agent; bh=xoJl8aTlh9L4SCH5daGjPY3CAuwdjbn3W0lK0xi0Cko=; b=O7l1Er+WyDvU7QKJdI/qTNMe+zXw3XfLNwQqMWrUDFh4avmdsT+G3akYncNJHkgQqp n8eGR+WER5FerloUB48GZWR2fFGuNlagqwwBnxnkSAXWzSzucfXchs1N2sN4tyJvro7u enfxXpf92VKGAWhMrGcjXV/+/8Okx+RUtdPkvBofCfoqc/+4DWr7N4/UNlOROwqAbMPf B2T58RSPD4MUGYkFPE8hoxqPX5vzjeUOfK/6946KLq6S2HnmqhqU3XnqbS8BwOhWRvJ1 wM++RSI3a1FhBNE+GHQCdhmdibjwbJAxMLTRI8T26eTFBH4JtQctZ0fQ95biSewKrQKI Mq8w== X-Gm-Message-State: AOAM5332JLuPsbUb5DHvoKn+LkT7pZXSDb5I30XjwD3Um1v1Py5SEfwt GgBK15W4j53Pl7jetA0a1WoFXnhFYNuGyg== X-Google-Smtp-Source: ABdhPJw23yohmCYT8BySqP18sgXGYVhVmT7iICYmiRx7uWNzGv7jrEXmy/LJ9CZVCA9NHl7l6w3kmg== X-Received: by 2002:a92:c14f:0:b0:2c5:ba03:f8f5 with SMTP id b15-20020a92c14f000000b002c5ba03f8f5mr4040145ilh.179.1646256834737; Wed, 02 Mar 2022 13:33:54 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 7-20020a056e0220c700b002c22480d578sm122493ilq.66.2022.03.02.13.33.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Mar 2022 13:33:54 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id D4DF2800E60; Wed, 2 Mar 2022 15:33:52 -0600 (CST) Date: Wed, 2 Mar 2022 15:33:52 -0600 From: Justin Pryzby To: Daniil Zakhlystov Cc: pgsql-hackers@lists.postgresql.org, Andrey Borodin Subject: Re: libpq compression (part 2) Message-ID: <20220302213352.GA27651@telsasoft.com> References: <20220112141526.GF14051@telsasoft.com> <20220113235827.GM14051@telsasoft.com> <18CFC392-0391-4439-9F02-FC1CF02FFA24@yandex-team.ru> <20220118043919.GA23027@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220118043919.GA23027@telsasoft.com> 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 If there's no objection, I'd like to move this to the next CF for consideration in PG16. On Mon, Jan 17, 2022 at 10:39:19PM -0600, Justin Pryzby wrote: > On Tue, Jan 18, 2022 at 02:06:32AM +0500, Daniil Zakhlystov wrote: > > > => Since March, errmsg doesn't need extra parenthesis around it (e3a87b4). > > > I’ve resolved the stuck tests and added zlib support for CI Windows builds to patch 0003-*. Thanks > > for the suggestion, all tests seem to be OK now, except the macOS one. It won't schedule in Cirrus > > CI for some reason, but I guess it happens because of my GitHub account limitation. > > I don't know about your github account, but it works for cfbot, which is now > green. > > Thanks for implementing zlib for windows. Did you try this with default > compressions set to lz4 and zstd ? > > The thread from 2019 is very long, and starts off with the guidance that > compression had been implemented at the wrong layer. It looks like this hasn't > changed since then. secure_read/write are passed as function pointers to the > ZPQ interface, which then calls back to them to read and flush its compression > buffers. As I understand, the suggestion was to leave the socket reads and > writes alone. And then conditionally de/compress buffers after reading / > before writing from the socket if compression was negotiated. > > It's currently done like this > pq_recvbuf() => secure_read() - when compression is disabled > pq_recvbuf() => ZPQ => secure_read() - when compression is enabled > > Dmitri sent a partial, POC patch which changes the de/compression to happen in > secure_read/write, which is changed to call ZPQ: > https://www.postgresql.org/message-id/CA+q6zcUPrssNaRS+FyoBsD-F2stK1Roa-4sAhFOfAjOWLziM4g@mail.gmail.com > pq_recvbuf() => secure_read() => ZPQ > > The same thing is true of the frontend: function pointers to > pqsecure_read/write are being passed to zpq_create, and then the ZPQ interface > called instead of the original functions. Those are the functions which read > using SSL, so they should also handle compression. > > That's where SSL is handled, and it seems like the right place to handle > compression. Have you evaluated that way to do things ? > > Konstantin said he put ZPQ at that layer seems to 1) avoid code duplication > between client/server; and, 2) to allow compression to happen before SSL, to > allow both (if the admin decides it's okay). But I don't see why compression > can't happen before sending to SSL, or after reading from it?