forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita4adc31
committed
lwlock: Fix quadratic behavior with very long wait lists
Until now LWLockDequeueSelf() sequentially searched the list of waiters to seeif the current proc is still is on the list of waiters, or has already beenremoved. In extreme workloads, where the wait lists are very long, this leadsto a quadratic behavior. #backends iterating over a list #backendslong. Additionally, the likelihood of needing to call LWLockDequeueSelf() inthe first place also increases with the increased length of the wait queue, asit becomes more likely that a lock is released while waiting for the wait listlock, which is held for longer during lock release.Due to the exponential back-off in perform_spin_delay() this is surprisinglyhard to detect. We should make that easier, e.g. by adding a wait event aroundthe pg_usleep() - but that's a separate patch.The fix is simple - track whether a proc is currently waiting in the wait listor already removed but waiting to be woken up in PGPROC->lwWaiting.In some workloads with a lot of clients contending for a small number oflwlocks (e.g. WALWriteLock), the fix can substantially increase throughput.As the quadratic behavior arguably is a bug, we might want to decide tobackpatch this fix in the future.Author: Andres Freund <andres@anarazel.de>Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>Discussion:https://postgr.es/m/20221027165914.2hofzp4cvutj6gin@awork3.anarazel.deDiscussion:https://postgr.es/m/CALj2ACXktNbG=K8Xi7PSqbofTZozavhaxjatVc14iYaLu4Maag@mail.gmail.com1 parent061bf98 commita4adc31
File tree
5 files changed
+42
-27
lines changed- src
- backend
- access/transam
- storage/lmgr
- include/storage
5 files changed
+42
-27
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
485 | 485 |
| |
486 | 486 |
| |
487 | 487 |
| |
488 |
| - | |
| 488 | + | |
489 | 489 |
| |
490 | 490 |
| |
491 | 491 |
| |
|
Lines changed: 30 additions & 23 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
982 | 982 |
| |
983 | 983 |
| |
984 | 984 |
| |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
985 | 994 |
| |
986 | 995 |
| |
987 | 996 |
| |
| |||
1039 | 1048 |
| |
1040 | 1049 |
| |
1041 | 1050 |
| |
1042 |
| - | |
| 1051 | + | |
1043 | 1052 |
| |
1044 | 1053 |
| |
1045 | 1054 |
| |
| |||
1060 | 1069 |
| |
1061 | 1070 |
| |
1062 | 1071 |
| |
1063 |
| - | |
| 1072 | + | |
1064 | 1073 |
| |
1065 | 1074 |
| |
1066 | 1075 |
| |
1067 | 1076 |
| |
1068 | 1077 |
| |
1069 | 1078 |
| |
1070 | 1079 |
| |
1071 |
| - | |
| 1080 | + | |
1072 | 1081 |
| |
1073 | 1082 |
| |
1074 | 1083 |
| |
| |||
1095 | 1104 |
| |
1096 | 1105 |
| |
1097 | 1106 |
| |
1098 |
| - | |
1099 |
| - | |
| 1107 | + | |
1100 | 1108 |
| |
1101 | 1109 |
| |
1102 | 1110 |
| |
| |||
1109 | 1117 |
| |
1110 | 1118 |
| |
1111 | 1119 |
| |
1112 |
| - | |
1113 |
| - | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
1114 | 1123 |
| |
1115 |
| - | |
1116 |
| - | |
1117 |
| - | |
1118 |
| - | |
1119 |
| - | |
1120 |
| - | |
1121 |
| - | |
1122 |
| - | |
1123 |
| - | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
1124 | 1127 |
| |
1125 | 1128 |
| |
1126 | 1129 |
| |
| |||
1132 | 1135 |
| |
1133 | 1136 |
| |
1134 | 1137 |
| |
1135 |
| - | |
1136 |
| - | |
| 1138 | + | |
| 1139 | + | |
1137 | 1140 |
| |
1138 | 1141 |
| |
1139 | 1142 |
| |
| |||
1157 | 1160 |
| |
1158 | 1161 |
| |
1159 | 1162 |
| |
1160 |
| - | |
| 1163 | + | |
1161 | 1164 |
| |
1162 | 1165 |
| |
1163 | 1166 |
| |
| |||
1308 | 1311 |
| |
1309 | 1312 |
| |
1310 | 1313 |
| |
1311 |
| - | |
| 1314 | + | |
1312 | 1315 |
| |
1313 | 1316 |
| |
1314 | 1317 |
| |
| |||
1473 | 1476 |
| |
1474 | 1477 |
| |
1475 | 1478 |
| |
1476 |
| - | |
| 1479 | + | |
1477 | 1480 |
| |
1478 | 1481 |
| |
1479 | 1482 |
| |
| |||
1689 | 1692 |
| |
1690 | 1693 |
| |
1691 | 1694 |
| |
1692 |
| - | |
| 1695 | + | |
1693 | 1696 |
| |
1694 | 1697 |
| |
1695 | 1698 |
| |
| |||
1767 | 1770 |
| |
1768 | 1771 |
| |
1769 | 1772 |
| |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
1770 | 1777 |
| |
1771 | 1778 |
| |
1772 | 1779 |
| |
| |||
1782 | 1789 |
| |
1783 | 1790 |
| |
1784 | 1791 |
| |
1785 |
| - | |
| 1792 | + | |
1786 | 1793 |
| |
1787 | 1794 |
| |
1788 | 1795 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
397 | 397 |
| |
398 | 398 |
| |
399 | 399 |
| |
400 |
| - | |
| 400 | + | |
401 | 401 |
| |
402 | 402 |
| |
403 | 403 |
| |
| |||
579 | 579 |
| |
580 | 580 |
| |
581 | 581 |
| |
582 |
| - | |
| 582 | + | |
583 | 583 |
| |
584 | 584 |
| |
585 | 585 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
26 | 34 |
| |
27 | 35 |
| |
28 | 36 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
217 | 217 |
| |
218 | 218 |
| |
219 | 219 |
| |
220 |
| - | |
| 220 | + | |
221 | 221 |
| |
222 | 222 |
| |
223 | 223 |
| |
|
0 commit comments
Comments
(0)