forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit71e4cc6
committed
Optimize WAL insertion lock acquisition and release with some atomics
The WAL insertion lock variable insertingAt is currently being readand written with the help of the LWLock wait list lock to avoid any readof torn values. This wait list lock can become a point of contention ona highly concurrent write workloads.This commit switches insertingAt to a 64b atomic variable that providestorn-free reads/writes. On platforms without 64b atomic support, thefallback implementation uses spinlocks to provide the same guaranteesfor the values read. LWLockWaitForVar(), throughLWLockConflictsWithVar(), reads the new value to check if it still needsto wait with a u64 atomic operation. LWLockUpdateVar() updates thevariable before waking up the waiters with an exchange_u64 (full memorybarrier). LWLockReleaseClearVar() now uses also an exchange_u64 toreset the variable. Before this commit, all these steps relied onLWLockWaitListLock() and LWLockWaitListUnlock().This reduces contention on LWLock wait list lock and improvesperformance of highly-concurrent write workloads. Here are somenumbers using pg_logical_emit_message() (HEAD atd6677b9) with variousarbitrary record lengths and clients up to 1k on a rather-large machine(64 vCPUs, 512GB of RAM, 16 cores per sockets, 2 sockets), in terms ofTPS numbers coming from pgbench: message_size_b | 16 | 64 | 256 | 1024--------------------+--------+--------+--------+------- patch_4_clients | 83830 | 82929 | 80478 | 73131 patch_16_clients | 267655 | 264973 | 250566 | 213985 patch_64_clients | 380423 | 378318 | 356907 | 294248 patch_256_clients | 360915 | 354436 | 326209 | 263664 patch_512_clients | 332654 | 321199 | 287521 | 240128 patch_1024_clients | 288263 | 276614 | 258220 | 217063 patch_2048_clients | 252280 | 243558 | 230062 | 192429 patch_4096_clients | 212566 | 213654 | 205951 | 166955 head_4_clients | 83686 | 83766 | 81233 | 73749 head_16_clients | 266503 | 265546 | 249261 | 213645 head_64_clients | 366122 | 363462 | 341078 | 261707 head_256_clients | 132600 | 132573 | 134392 | 165799 head_512_clients | 118937 | 114332 | 116860 | 150672 head_1024_clients | 133546 | 115256 | 125236 | 151390 head_2048_clients | 137877 | 117802 | 120909 | 138165 head_4096_clients | 113440 | 115611 | 120635 | 114361Bharath has been measuring similar improvements, where the limit of theWAL insertion lock begins to be felt when more than 256 concurrentclients are involved in this specific workload.An extra patch has been discussed to introduce a fast-exit path inLWLockUpdateVar() when there are no waiters, still this does notinfluence the write-heavy workload cases discussed as there are alwayswaiters. This will be considered separately.Author: Bharath RupireddyReviewed-by: Nathan Bossart, Andres Freund, Michael PaquierDiscussion:https://postgr.es/m/CALj2ACVF+6jLvqKe6xhDzCCkr=rfd6upaGc3477Pji1Ke9G7Bg@mail.gmail.com1 parentd38ad8e commit71e4cc6
3 files changed
+26
-30
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
376 | 376 |
| |
377 | 377 |
| |
378 | 378 |
| |
379 |
| - | |
| 379 | + | |
380 | 380 |
| |
381 | 381 |
| |
382 | 382 |
| |
| |||
4611 | 4611 |
| |
4612 | 4612 |
| |
4613 | 4613 |
| |
4614 |
| - | |
| 4614 | + | |
4615 | 4615 |
| |
4616 | 4616 |
| |
4617 | 4617 |
| |
|
Lines changed: 21 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1547 | 1547 |
| |
1548 | 1548 |
| |
1549 | 1549 |
| |
1550 |
| - | |
1551 |
| - | |
1552 |
| - | |
| 1550 | + | |
| 1551 | + | |
1553 | 1552 |
| |
1554 | 1553 |
| |
1555 | 1554 |
| |
| |||
1572 | 1571 |
| |
1573 | 1572 |
| |
1574 | 1573 |
| |
1575 |
| - | |
1576 |
| - | |
1577 |
| - | |
| 1574 | + | |
| 1575 | + | |
1578 | 1576 |
| |
1579 |
| - | |
1580 |
| - | |
1581 |
| - | |
| 1577 | + | |
1582 | 1578 |
| |
1583 | 1579 |
| |
1584 | 1580 |
| |
| |||
1607 | 1603 |
| |
1608 | 1604 |
| |
1609 | 1605 |
| |
1610 |
| - | |
| 1606 | + | |
| 1607 | + | |
1611 | 1608 |
| |
1612 | 1609 |
| |
1613 | 1610 |
| |
| |||
1735 | 1732 |
| |
1736 | 1733 |
| |
1737 | 1734 |
| |
1738 |
| - | |
1739 |
| - | |
1740 |
| - | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
1741 | 1738 |
| |
1742 | 1739 |
| |
1743 | 1740 |
| |
1744 | 1741 |
| |
1745 |
| - | |
| 1742 | + | |
1746 | 1743 |
| |
1747 | 1744 |
| |
1748 | 1745 |
| |
1749 | 1746 |
| |
1750 | 1747 |
| |
1751 | 1748 |
| |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
1752 | 1755 |
| |
1753 | 1756 |
| |
1754 | 1757 |
| |
1755 | 1758 |
| |
1756 | 1759 |
| |
1757 | 1760 |
| |
1758 |
| - | |
1759 |
| - | |
1760 |
| - | |
1761 | 1761 |
| |
1762 | 1762 |
| |
1763 | 1763 |
| |
| |||
1873 | 1873 |
| |
1874 | 1874 |
| |
1875 | 1875 |
| |
1876 |
| - | |
| 1876 | + | |
1877 | 1877 |
| |
1878 |
| - | |
1879 |
| - | |
1880 | 1878 |
| |
1881 |
| - | |
1882 |
| - | |
1883 |
| - | |
| 1879 | + | |
| 1880 | + | |
1884 | 1881 |
| |
1885 |
| - | |
1886 |
| - | |
| 1882 | + | |
1887 | 1883 |
| |
1888 | 1884 |
| |
1889 | 1885 |
| |
|
Lines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
129 | 129 |
| |
130 | 130 |
| |
131 | 131 |
| |
132 |
| - | |
| 132 | + | |
133 | 133 |
| |
134 | 134 |
| |
135 | 135 |
| |
136 | 136 |
| |
137 | 137 |
| |
138 |
| - | |
139 |
| - | |
| 138 | + | |
| 139 | + | |
140 | 140 |
| |
141 | 141 |
| |
142 | 142 |
| |
|
0 commit comments
Comments
(0)