Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPXsv-0003CB-RY for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Jul 2016 16:28:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bPXsv-0008Gb-AJ for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Jul 2016 16:28:41 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bPXsu-0008GU-Rh for pgsql-bugs@postgresql.org; Tue, 19 Jul 2016 16:28:40 +0000 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bPXsr-0000I1-31 for pgsql-bugs@postgresql.org; Tue, 19 Jul 2016 16:28:39 +0000 Received: by mail-lf0-x235.google.com with SMTP id l69so19003585lfg.1 for ; Tue, 19 Jul 2016 09:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=9YfrrmexII9iOG92gEr+C7trjjTth9w013+s7GZck3w=; b=QwifYGo9u8rGOcR/QDreTLNBrnbLWAuYFhu/PA/XWcvzUzw1lz8USqlaaut4UZhBX4 0Ss85G4bk0UDJzGrGHIpCmQZObJGYIuTkegnrT7D55InGsMjisuy144A5DN2n2fKQDml b7fmi0qGhq/n0y76y4tWDBzA0PpfMyIhP2X2OByroyhoqsgazsHXS4gSrU2vhF6yG6tp Ea1RhsxD6QbIvfVCi2o0xf9WzAs2vY+RpEF4ZqbTjqgyiOtG3Vz0c9XKlg/FsRc6euJp xOuuI83FOcJdlxPSiEUacq9bzQPY3czmunGOkBS0+rjsCoCpjlYKNiN0e+OubAfSeD+c 8PHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=9YfrrmexII9iOG92gEr+C7trjjTth9w013+s7GZck3w=; b=JIvEy3VDtoeQQGeOjWxZNo5oGuzlZmFchsYT9f7helAIFeqdQ9I0wzkPiEcloSf6k3 ngIKIadJQxtVg7OhxGGKuXHOoR5ZpWnsWPZIl9K8zKUrS/hLEJc6oErNLwkvyqOt4mDo CM4I0NPvkYmNPF32JY4boheouKOATQV+fddgy7+R34zLKldwAeTcf5bMs4/PLleD5/N/ DYkuW7s8WKiXvLzE/dNwrY+qA0c8UZ3NPGgNa2A3NizxsexoAWLkvCKv+MK+6ugNtQ0N bQGBGiUqnrnY+Wp9Nkn6oTekraxd+JhFvx9xmkNHMYLfCcyPOFG+UduZ2ctrzoVEPpcl psng== X-Gm-Message-State: ALyK8tL1sx7NsL0OMJtpCWPzjbA8QlnELiiEMl6iEGuHfCCwt7YSyj92jf9FPnd7NH5FzEOt X-Received: by 10.25.218.12 with SMTP id r12mr6025401lfg.50.1468945716120; Tue, 19 Jul 2016 09:28:36 -0700 (PDT) Received: from [10.137.2.17] (ip-89-177-44-58.net.upcbroadband.cz. [89.177.44.58]) by smtp.gmail.com with ESMTPSA id 67sm6072200ljj.8.2016.07.19.09.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 09:28:35 -0700 (PDT) Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function To: Andres Freund References: <878txea5b4.fsf@news-spur.riddles.org.uk> <20160706212600.GA649263@alvherre.pgsql> <8ec28b02-6ae5-369c-ec33-a7f59172c935@2ndquadrant.com> <20160719052751.5arxjvgkr34q6iff@alap3.anarazel.de> <613a6533-1f20-d8eb-c852-414fd159c758@2ndquadrant.com> Cc: Peter Geoghegan , Alvaro Herrera , pgsql-bugs@postgresql.org, Andrew Gierth , blake@rcmail.com From: Tomas Vondra Message-ID: <37deb733-d364-1d23-3aa6-f3d88acd18f0@2ndquadrant.com> Date: Tue, 19 Jul 2016 18:28:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: <613a6533-1f20-d8eb-c852-414fd159c758@2ndquadrant.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 07/19/2016 06:22 PM, Tomas Vondra wrote: > > [one huge cup of coffee later ...] > > So, I think it's actually quite simple to improve this by using a > generational design, i.e. creating a sequence of slab contexts every N > tuples, using the average tuple length from the previous batch as input > for the next one (multiplied by 1.5x to give a bit of slack). Maybe this > heuristics is far too simple, but perhaps we can > > Attached is a v2 of the patch doing pretty much this - I wouldn't call > this even half-baked, it's a rather early PoC thingy. But it seems to > work, and for the test case from the initial report, it significantly > reduces memory consumption by a factor of 100x, as the average tuple > length is ~80B, not 8kB. It increases the runtime a bit (say, from 700ms > to 800ms for the 100k test case), but that seems negligible compared to > the master behavior and worth considering the memory consumption reduction. > > This relies on one of the SlabContext features - it can easily see which > blocks are free because it has 'free bitmap' in each block, so old > contexts get automatically freed once the tuples are pfreed. I have not > made any attempt to free the context structure itself, which is a memory > leak, but I feel lazy and it's good enough for a PoC. > > The AllocSet obviously can't do that, so that part is not part of the > generation design - it would just prevent reuse of the memory, thus > increasing memory consumption. But if we could make the AllocSet capable > of doing AllocSetIsEmpty reasonably (and not just when it's reset, which > is pretty useless I believe), we could discard the whole context (making > the generational design viable). > Heck, we could even implement this as a special type of memory context, suitable for cases with mostly the same palloc sizes (but not entirely constant, as required by the SlabContext as implemented in the patch). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs