forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitdc7420c
committed
snapshot scalability: Don't compute global horizons while building snapshots.
To make GetSnapshotData() more scalable, it cannot not look at at each proc'sxmin: While snapshot contents do not need to change whenever a read-onlytransaction commits or a snapshot is released, a proc's xmin is modified inthose cases. The frequency of xmin modifications leads to, particularly onhigher core count systems, many cache misses inside GetSnapshotData(), despitethe data underlying a snapshot not changing. That is the mostsignificant source of GetSnapshotData() scaling poorly on larger systems.Without accessing xmins, GetSnapshotData() cannot calculate accurate horizons /thresholds as it has so far. But we don't really have to: The horizons don'tactually change that much between GetSnapshotData() calls. Nor are the horizonsactually used every time a snapshot is built.The trick this commit introduces is to delay computation of accurate horizonsuntil there use and using horizon boundaries to determine whether accuratehorizons need to be computed.The use of RecentGlobal[Data]Xmin to decide whether a row version could beremoved has been replaces with new GlobalVisTest* functions. These use twothresholds to determine whether a row can be pruned:1) definitely_needed, indicating that rows deleted by XIDs >= definitely_needed are definitely still visible.2) maybe_needed, indicating that rows deleted by XIDs < maybe_needed can definitely be removedGetSnapshotData() updates definitely_needed to be the xmin of the computedsnapshot.When testing whether a row can be removed (with GlobalVisTestIsRemovableXid())and the tested XID falls in between the two (i.e. XID >= maybe_needed && XID <definitely_needed) the boundaries can be recomputed to be more accurate. As itis not cheap to compute accurate boundaries, we limit the number of times thathappens in short succession. As the boundaries used byGlobalVisTestIsRemovableXid() are never reset (with maybe_needed updated byGetSnapshotData()), it is likely that further test can benefit from an earliercomputation of accurate horizons.To avoid regressing performance when old_snapshot_threshold is set (as thatrequires an accurate horizon to be computed), heap_page_prune_opt() doesn'tunconditionally call TransactionIdLimitedForOldSnapshots() anymore. Both thecomputation of the limited horizon, and the triggering of errors (withSetOldSnapshotThresholdTimestamp()) is now only done when necessary to removetuples.This commit just removes the accesses to PGXACT->xmin fromGetSnapshotData(), but other members of PGXACT residing in the samecache line are accessed. Therefore this in itself does not result in asignificant improvement. Subsequent commits will take advantage of thefact that GetSnapshotData() now does not need to access xmins anymore.Note: This contains a workaround in heap_page_prune_opt() to keep thesnapshot_too_old tests working. While that workaround is ugly, the testscurrently are not meaningful, and it seems best to address them separately.Author: Andres Freund <andres@anarazel.de>Reviewed-By: Robert Haas <robertmhaas@gmail.com>Reviewed-By: Thomas Munro <thomas.munro@gmail.com>Reviewed-By: David Rowley <dgrowleyml@gmail.com>Discussion:https://postgr.es/m/20200301083601.ews6hz5dduc3w2se@alap3.anarazel.de1 parent1f42d35 commitdc7420c
File tree
38 files changed
+1462
-566
lines changed- contrib
- amcheck
- pg_visibility
- pgstattuple
- src
- backend
- access
- gin
- gist
- heap
- index
- nbtree
- spgist
- transam
- commands
- postmaster
- replication
- logical
- storage/ipc
- utils
- adt
- init
- time
- include
- access
- storage
- utils
- tools/pgindent
38 files changed
+1462
-566
lines changedLines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
434 | 434 |
| |
435 | 435 |
| |
436 | 436 |
| |
437 |
| - | |
438 |
| - | |
| 437 | + | |
| 438 | + | |
439 | 439 |
| |
440 |
| - | |
| 440 | + | |
441 | 441 |
| |
442 | 442 |
| |
443 | 443 |
| |
| |||
1581 | 1581 |
| |
1582 | 1582 |
| |
1583 | 1583 |
| |
1584 |
| - | |
| 1584 | + | |
1585 | 1585 |
| |
1586 | 1586 |
| |
1587 | 1587 |
| |
|
Lines changed: 8 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
563 | 563 |
| |
564 | 564 |
| |
565 | 565 |
| |
566 |
| - | |
567 |
| - | |
568 |
| - | |
569 |
| - | |
570 |
| - | |
571 |
| - | |
572 | 566 |
| |
573 | 567 |
| |
574 | 568 |
| |
575 | 569 |
| |
576 | 570 |
| |
| 571 | + | |
| 572 | + | |
| 573 | + | |
577 | 574 |
| |
578 | 575 |
| |
579 | 576 |
| |
| |||
679 | 676 |
| |
680 | 677 |
| |
681 | 678 |
| |
682 |
| - | |
683 |
| - | |
684 |
| - | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
685 | 683 |
| |
686 |
| - | |
| 684 | + | |
687 | 685 |
| |
688 | 686 |
| |
689 | 687 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
71 | 71 |
| |
72 | 72 |
| |
73 | 73 |
| |
74 |
| - | |
| 74 | + | |
75 | 75 |
| |
76 | 76 |
| |
77 | 77 |
| |
|
Lines changed: 26 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
793 | 793 |
| |
794 | 794 |
| |
795 | 795 |
| |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + |
Lines changed: 3 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
891 | 891 |
| |
892 | 892 |
| |
893 | 893 |
| |
894 |
| - | |
895 |
| - | |
| 894 | + | |
| 895 | + | |
896 | 896 |
| |
897 | 897 |
| |
898 | 898 |
| |
899 |
| - | |
900 | 899 |
| |
901 |
| - | |
902 |
| - | |
| 900 | + | |
903 | 901 |
| |
904 | 902 |
| |
905 | 903 |
| |
|
Lines changed: 5 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
387 | 387 |
| |
388 | 388 |
| |
389 | 389 |
| |
390 |
| - | |
391 |
| - | |
392 |
| - | |
393 |
| - | |
394 |
| - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
395 | 395 |
| |
396 | 396 |
| |
397 | 397 |
| |
|
Lines changed: 11 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1517 | 1517 |
| |
1518 | 1518 |
| |
1519 | 1519 |
| |
| 1520 | + | |
1520 | 1521 |
| |
1521 | 1522 |
| |
1522 | 1523 |
| |
| |||
1527 | 1528 |
| |
1528 | 1529 |
| |
1529 | 1530 |
| |
1530 |
| - | |
| 1531 | + | |
| 1532 | + | |
1531 | 1533 |
| |
1532 | 1534 |
| |
1533 | 1535 |
| |
| |||
1616 | 1618 |
| |
1617 | 1619 |
| |
1618 | 1620 |
| |
1619 |
| - | |
1620 |
| - | |
1621 |
| - | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
1622 | 1629 |
| |
1623 | 1630 |
| |
1624 | 1631 |
| |
|
Lines changed: 12 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1203 | 1203 |
| |
1204 | 1204 |
| |
1205 | 1205 |
| |
1206 |
| - | |
| 1206 | + | |
1207 | 1207 |
| |
1208 | 1208 |
| |
1209 | 1209 |
| |
| |||
1244 | 1244 |
| |
1245 | 1245 |
| |
1246 | 1246 |
| |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
1247 | 1258 |
| |
1248 | 1259 |
| |
1249 | 1260 |
| |
| |||
1263 | 1274 |
| |
1264 | 1275 |
| |
1265 | 1276 |
| |
1266 |
| - | |
1267 |
| - | |
1268 |
| - | |
1269 |
| - | |
1270 |
| - | |
1271 |
| - | |
1272 |
| - | |
1273 |
| - | |
1274 |
| - | |
1275 |
| - | |
1276 |
| - | |
1277 | 1277 |
| |
1278 | 1278 |
| |
1279 | 1279 |
| |
|
Lines changed: 73 additions & 26 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1154 | 1154 |
| |
1155 | 1155 |
| |
1156 | 1156 |
| |
1157 |
| - | |
1158 |
| - | |
1159 |
| - | |
1160 |
| - | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
1161 | 1162 |
| |
1162 | 1163 |
| |
1163 | 1164 |
| |
1164 | 1165 |
| |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1165 | 1199 |
| |
1166 | 1200 |
| |
1167 | 1201 |
| |
1168 | 1202 |
| |
1169 | 1203 |
| |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
1170 | 1207 |
| |
1171 | 1208 |
| |
1172 | 1209 |
| |
| |||
1323 | 1360 |
| |
1324 | 1361 |
| |
1325 | 1362 |
| |
1326 |
| - | |
1327 |
| - | |
1328 |
| - | |
1329 |
| - | |
1330 |
| - | |
1331 |
| - | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1332 | 1369 |
| |
1333 |
| - | |
1334 |
| - | |
1335 |
| - | |
1336 |
| - | |
| 1370 | + | |
| 1371 | + | |
1337 | 1372 |
| |
1338 | 1373 |
| |
1339 | 1374 |
| |
| |||
1372 | 1407 |
| |
1373 | 1408 |
| |
1374 | 1409 |
| |
1375 |
| - | |
1376 |
| - | |
| 1410 | + | |
| 1411 | + | |
1377 | 1412 |
| |
1378 |
| - | |
1379 |
| - | |
1380 |
| - | |
1381 |
| - | |
1382 |
| - | |
| 1413 | + | |
| 1414 | + | |
1383 | 1415 |
| |
1384 | 1416 |
| |
1385 | 1417 |
| |
| |||
1393 | 1425 |
| |
1394 | 1426 |
| |
1395 | 1427 |
| |
1396 |
| - | |
| 1428 | + | |
1397 | 1429 |
| |
1398 | 1430 |
| |
1399 | 1431 |
| |
1400 | 1432 |
| |
1401 | 1433 |
| |
1402 |
| - | |
1403 |
| - | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
1404 | 1450 |
| |
1405 | 1451 |
| |
1406 | 1452 |
| |
| |||
1418 | 1464 |
| |
1419 | 1465 |
| |
1420 | 1466 |
| |
1421 |
| - | |
| 1467 | + | |
1422 | 1468 |
| |
1423 | 1469 |
| |
1424 | 1470 |
| |
| |||
1459 | 1505 |
| |
1460 | 1506 |
| |
1461 | 1507 |
| |
1462 |
| - | |
| 1508 | + | |
| 1509 | + | |
1463 | 1510 |
| |
1464 | 1511 |
| |
1465 | 1512 |
| |
|
0 commit comments
Comments
(0)