Re: PATCH: logical_work_mem and logical streaming of large in-progress transactions
Amit Kapila <amit.kapila16@gmail.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Tighten the concurrent abort check during decoding.
- 2ce353fc1902 14.0 landed
-
Improve hash_create()'s API for some added robustness.
- b3817f5f7746 14.0 landed
-
Use HASH_BLOBS for xidhash.
- a1b8aa1e4eec 14.0 landed
-
Fix initialization of RelationSyncEntry for streaming transactions.
- 69bd60672af6 14.0 landed
-
Remove unused function declaration in logicalproto.h.
- ddd5f6d2609b 14.0 landed
-
Add additional tests to test streaming of in-progress transactions.
- 58b5ae9d62bd 14.0 landed
-
Fix inline marking introduced in commit 464824323e.
- ac15b499f7f9 14.0 landed
-
Add support for streaming to built-in logical replication.
- 464824323e57 14.0 landed
-
Fix the SharedFileSetUnregister API.
- 4ab77697f67a 14.0 landed
-
Fix comment in procarray.c
- 77c7267c37f7 14.0 cited
-
Suppress compiler warning in non-cassert builds.
- e942af7b8261 14.0 cited
-
Extend the BufFile interface.
- 808e13b282ef 14.0 landed
-
Mark a few logical decoding related variables with PGDLLIMPORT.
- b48cac3b10a0 14.0 landed
-
Implement streaming mode in ReorderBuffer.
- 7259736a6e5b 14.0 landed
-
Extend the logical decoding output plugin API with stream methods.
- 45fdc9738b36 14.0 landed
-
WAL Log invalidations at command end with wal_level=logical.
- c55040ccd017 14.0 landed
-
Immediately WAL-log subtransaction and top-level XID association.
- 0bead9af484c 14.0 landed
-
Allow logical replication to transfer data in binary format.
- 9de77b545313 14.0 cited
-
Only superuser can set sslcert/sslkey in postgres_fdw user mappings
- cebf9d6e6ee1 13.0 cited
-
Track statistics for spilling of changes from ReorderBuffer.
- 9290ad198b15 13.0 landed
-
Add logical_decoding_work_mem to limit ReorderBuffer memory usage.
- cec2edfa7859 13.0 landed
-
logical decoding: process ASSIGNMENT during snapshot build
- bac2fae05c77 13.0 cited
-
Emit invalidations to standby for transactions without xid.
- c6ff84b06a68 9.6.0 cited
On Fri, Sep 27, 2019 at 12:06 AM Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote: > > On Thu, Sep 26, 2019 at 06:58:17PM +0530, Amit Kapila wrote: > > >3. > >+ * Find the largest transaction (toplevel or subxact) to evict (spill to disk). > >+ * > >+ * XXX With many subtransactions this might be quite slow, because we'll have > >+ * to walk through all of them. There are some options how we could improve > >+ * that: (a) maintain some secondary structure with transactions sorted by > >+ * amount of changes, (b) not looking for the entirely largest transaction, > >+ * but e.g. for transaction using at least some fraction of the memory limit, > >+ * and (c) evicting multiple transactions at once, e.g. to free a given portion > >+ * of the memory limit (e.g. 50%). > >+ */ > >+static ReorderBufferTXN * > >+ReorderBufferLargestTXN(ReorderBuffer *rb) > > > >What is the guarantee that after evicting largest transaction, we > >won't immediately hit the memory limit? Say, all of the transactions > >are of almost similar size which I don't think is that uncommon a > >case. > > Not sure I understand - what do you mean 'immediately hit'? > > We do check the limit after queueing a change, and we know that this > change is what got us over the limit. We pick the largest transaction > (which has to be larger than the change we just entered) and evict it, > getting below the memory limit again. > > The next change can get us over the memory limit again, of course, > Yeah, this is what I want to say when I wrote that it can immediately hit again. > but > there's not much we could do about that. > > > Instead, the strategy mentioned in point (c) or something like > >that seems more promising. In that strategy, there is some risk that > >it might lead to many smaller disk writes which we might want to > >control via some threshold (like we should not flush more than N > >xacts). In this, we also need to ensure that the total memory freed > >must be greater than the current change. > > > >I think we have some discussion around this point but didn't reach any > >conclusion which means some more brainstorming is required. > > > > I agree it's worth investigating, but I'm not sure it's necessary before > committing v1 of the feature. I don't think there's a clear winner > strategy, and the current approach works fairly well I think. > > The comment is concerned with the cost of ReorderBufferLargestTXN with > many transactions, but we can only have certain number of top-level > transactions (max_connections + certain number of not-yet-assigned > subtransactions). And 0002 patch essentially gets rid of the subxacts > entirely, further reducing the maximum number of xacts to walk. > That would be good, but I don't understand how. The second patch will update the subxacts in top-level ReorderBufferTxn, but it won't remove it from hash table. It also doesn't seem to be caring for considering the size of subxacts in top-level xact, so not sure how will it reduce the number of xacts to walk. I might be missing something here. Can you explain a bit how 0002 patch would help in reducing the maximum number of xacts to walk? -- With Regards, Amit Kapila. EnterpriseDB: http://www.enterprisedb.com