From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Andres Freund <andres@anarazel.de>
Cc: Peter Geoghegan <pg@heroku.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: pgsql-bugs@postgresql.org, Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: blake@rcmail.com
Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function
Date: Tue, 19 Jul 2016 18:28:34 +0200
Message-ID: <37deb733-d364-1d23-3aa6-f3d88acd18f0@2ndquadrant.com> (raw)
In-Reply-To: <613a6533-1f20-d8eb-c852-414fd159c758@2ndquadrant.com>
References: <878txea5b4.fsf@news-spur.riddles.org.uk>
<20160706212600.GA649263@alvherre.pgsql>
<CAM3SWZSqBWmJEwu6-aFkN7XkPdybw_nrSfcjNtnJvq8m8-Rcig@mail.gmail.com>
<b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com>
<8ec28b02-6ae5-369c-ec33-a7f59172c935@2ndquadrant.com>
<20160719052751.5arxjvgkr34q6iff@alap3.anarazel.de>
<d4a5bf3c-f03b-92be-9f34-a772406f1817@2ndquadrant.com>
<613a6533-1f20-d8eb-c852-414fd159c758@2ndquadrant.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tomas.vondra@2ndquadrant.com, andres@anarazel.de, pg@heroku.com, alvherre@2ndquadrant.com, andrew@tao11.riddles.org.uk, blake@rcmail.com
Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function
In-Reply-To: <37deb733-d364-1d23-3aa6-f3d88acd18f0@2ndquadrant.com>
References: <878txea5b4.fsf@news-spur.riddles.org.uk> <20160706212600.GA649263@alvherre.pgsql> <CAM3SWZSqBWmJEwu6-aFkN7XkPdybw_nrSfcjNtnJvq8m8-Rcig@mail.gmail.com> <b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com> <8ec28b02-6ae5-369c-ec33-a7f59172c935@2ndquadrant.com> <20160719052751.5arxjvgkr34q6iff@alap3.anarazel.de> <d4a5bf3c-f03b-92be-9f34-a772406f1817@2ndquadrant.com> <613a6533-1f20-d8eb-c852-414fd159c758@2ndquadrant.com> <37deb733-d364-1d23-3aa6-f3d88acd18f0@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox