Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gufbY-0006GA-9s for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 15:40:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gufbW-0008Bb-Pn for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 15:40:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gufbW-0008BL-D1 for pgsql-hackers@lists.postgresql.org; Fri, 15 Feb 2019 15:40:42 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gufbT-0006cU-Nc for pgsql-hackers@lists.postgresql.org; Fri, 15 Feb 2019 15:40:42 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 521A321CEC76; Fri, 15 Feb 2019 18:40:38 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.200] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 0DE8B21CEC68; Fri, 15 Feb 2019 18:40:38 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1550245238; bh=BC7A3q7jBwPQIoG5tvMnY1OJaXXbJGDLdbiVuddE8Zk=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=iAS+EznMW1PuV/Cz99l10uy9XPTAO4N8966y+j++r7i9nC295iy8GEzk12Xj74nq5 3wQ86KoD4CjTYNIU6RPRFEaZtdfibQpdxgvJaena40YOy0Bb86lJ/WwXHAbKc9Jvzz 4vIlnCFbdmwl13DGGytsJsjrJhRgnhZdkypSsYRM= Subject: Re: libpq compression To: Tomas Vondra , Peter Eisentraut , Robbie Harwood , Thomas Munro Cc: Grigory Smolkin , PostgreSQL Hackers References: <429cf55b-a8bf-c4ba-196d-5b45420145a1@postgrespro.ru> <36db5d02-45e6-b863-1418-825ef20ae4c6@postgrespro.ru> <3b0260da-fe47-2341-da01-51383fe9172d@postgrespro.ru> <739641a6-f64d-0f2b-8483-34ab23e2dcd6@2ndquadrant.com> From: Konstantin Knizhnik Message-ID: Date: Fri, 15 Feb 2019 18:40:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <739641a6-f64d-0f2b-8483-34ab23e2dcd6@2ndquadrant.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 15.02.2019 18:26, Tomas Vondra wrote: > > > On 2/15/19 3:03 PM, Konstantin Knizhnik wrote: >> >> On 15.02.2019 15:42, Peter Eisentraut wrote: >>> On 2018-06-19 09:54, Konstantin Knizhnik wrote: >>>> The main drawback of streaming compression is that you can not >>>> decompress some particular message without decompression of all previous >>>> messages. >>> It seems this would have an adverse effect on protocol-aware connection >>> proxies: They would have to uncompress everything coming in and >>> recompress everything going out. >>> >>> The alternative of compressing each packet individually would work much >>> better: A connection proxy could peek into the packet header and only >>> uncompress the (few, small) packets that it needs for state and routing. >>> >> Individual compression of each message depreciate all idea of libpq >> compression. Messages are two small to efficiently compress each of >> them separately. So using streaming compression algorithm is >> absolutely necessary here. >> > Hmmm, I see Peter was talking about "packets" while you're talking about > "messages". Are you talking about the same thing? Sorry, but there are no "packet" in libpq protocol, so I assumed that packet=message. In any protocol-aware proxy has to proceed each message. > > Anyway, I was going to write about the same thing - that per-message > compression would likely eliminate most of the benefits - but I'm > wondering if it's actually true. That is, how much will the compression > ratio drop if we compress individual messages? Compression of small messages without shared dictionary will give awful results. Assume that average record and so message size is 100 bytes. Just perform very simple experiment create file with 100 equal characters and try to compress it. With zlib result will be 173 bytes. So after "compression" size of file is increase 1.7 times. This is why there is no other way to efficiently compress libpq traffic without usage of streaming compression (when dictionary isĀ  shared and updated for all messages). > > Obviously, if there are just tiny messages, it might easily eliminate > any benefits (and in fact it would add overhead). But I'd say we're way > more interested in transferring large data sets (result sets, data for > copy, etc.) and presumably those messages are much larger. So maybe we > could compress just those, somehow? Please notice that copy stream consists of individual messages for each record. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company