Re: Speed up Clog Access by increasing CLOG buffers
Amit Kapila <amit.kapila16@gmail.com>
On Sun, Mar 12, 2017 at 8:11 AM, Robert Haas <robertmhaas@gmail.com> wrote: > On Fri, Mar 10, 2017 at 7:39 PM, Amit Kapila <amit.kapila16@gmail.com> wrote: >> I agree that more analysis can help us to decide if we can use subxids >> from PGPROC and if so under what conditions. Have you considered the >> another patch I have posted to fix the issue which is to do this >> optimization only when subxids are not present? In that patch, it >> will remove the dependency of relying on subxids in PGPROC. > > Well, that's an option, but it narrows the scope of the optimization > quite a bit. I think Simon previously opposed handling only the > no-subxid cases (although I may be misremembering) and I'm not that > keen about it either. > > I was wondering about doing an explicit test: if the XID being > committed matches the one in the PGPROC, and nsubxids matches, and the > actual list of XIDs matches, then apply the optimization. That could > replace the logic that you've proposed to exclude non-commit cases, > gxact cases, etc. and it seems fundamentally safer. But it might be a > more expensive test, too, so I'm not sure. > I think if the number of subxids is very small let us say under 5 or so, then such a check might not matter, but otherwise it could be expensive. > It would be nice to get some other opinions on how (and whether) to > proceed with this. I'm feeling really nervous about this right at the > moment, because it seems like everybody including me missed some > fairly critical points relating to the safety (or lack thereof) of > this patch, and I want to make sure that if it gets committed again, > we've really got everything nailed down tight. > I think the basic thing that is missing in the last patch was that we can't apply this optimization during WAL replay as during recovery/hotstandby the xids/subxids are tracked in KnownAssignedXids. The same is mentioned in header file comments in procarray.c and in GetSnapshotData (look at an else loop of the check if (!snapshot->takenDuringRecovery)). As far as I can see, the patch has considered that in the initial versions but then the check got dropped in one of the later revisions by mistake. The patch version-5 [1] has the check for recovery, but during some code rearrangement, it got dropped in version-6 [2]. Having said that, I think the improvement in case there are subtransactions will be lesser because having subtransactions means more work under LWLock and that will have lesser context switches. This optimization is all about the reduction in frequent context switches, so I think even if we don't optimize the case for subtransactions we are not leaving much on the table and it will make this optimization much safe. To substantiate this theory with data, see the difference in performance when subtransactions are used [3] and when they are not used [4]. So we have four ways to proceed: 1. Have this optimization for subtransactions and make it safe by having some additional conditions like check for recovery, explicit check for if the actual transaction ids match with ids stored in proc. 2. Have this optimization when there are no subtransactions. In this case, we can have a very simple check for this optimization. 3. Drop this patch and idea. 4. Consider it for next version. I personally think second way is okay for this release as that looks safe and gets us the maximum benefit we can achieve by this optimization and then consider adding optimization for subtransactions (first way) in the future version if we think it is safe and gives us the benefit. Thoughts? [1] - https://www.postgresql.org/message-id/CAA4eK1KUVPxBcGTdOuKyvf5p1sQ0HeUbSMbTxtQc%3DP65OxiZog%40mail.gmail.com [2] - https://www.postgresql.org/message-id/CAA4eK1L4iV-2qe7AyMVsb%2Bnz7SiX8JvCO%2BCqhXwaiXgm3CaBUw%40mail.gmail.com [3] - https://www.postgresql.org/message-id/CAFiTN-u3%3DXUi7z8dTOgxZ98E7gL1tzL%3Dq9Yd%3DCwWCtTtS6pOZw%40mail.gmail.com [4] - https://www.postgresql.org/message-id/CAFiTN-u-XEzhd%3DhNGW586fmQwdTy6Qy6_SXe09tNB%3DgBcVzZ_A%40mail.gmail.com -- With Regards, Amit Kapila. EnterpriseDB: http://www.enterprisedb.com
Commits
-
Use group updates when setting transaction status in clog.
- baaf272ac908 11.0 landed
- ccce90b39867 10.0 landed
-
Improve 64bit atomics support.
- e8fdbd58fe56 10.0 landed
-
Add ProcArrayGroupUpdate wait event.
- d4116a771925 10.0 landed
-
Make the different Unix-y semaphore implementations ABI-compatible.
- be7b2848c6d8 10.0 cited
-
Fix broken ALTER INDEX documentation
- 2143f5e12790 9.6.0 cited
-
Code and docs review for commit 3187d6de0e5a9e805b27c48437897e8c39071d45.
- d12e5bb79bb5 9.6.0 cited
-
Partition the freelist for shared dynahash tables.
- 44ca4022f3f9 9.6.0 cited
-
Correct StartupSUBTRANS for page wraparound
- 481725c0ba73 9.6.0 cited
-
Make idle backends exit if the postmaster dies.
- ac1d7945f866 9.6.0 cited
-
contrib/sslinfo: add ssl_extension_info SRF
- 49124613f134 9.6.0 cited
-
Reduce ProcArrayLock contention by removing backends in batches.
- 0e141c0fbb21 9.6.0 cited
-
Fix `make installcheck` for serializable transactions.
- 253de7e1eb9a 9.6.0 cited
-
Lockless StrategyGetBuffer clock sweep hot path.
- d72731a70450 9.5.0 cited
-
Reduce sinval synchronization overhead.
- b4fbe392f8ff 9.2.0 cited