Skip to content

Commit 2201d80

Browse files
committed
Avoid extra locks in GetSnapshotData if old_snapshot_threshold < 0
On a big NUMA machine with 1000 connections in saturation load there was a performance regression due to spinlock contention, for acquiring values which were never used. Just fill with dummy values if we're not going to use them. This patch has not been benchmarked yet on a big NUMA machine, but it seems like a good idea on general principle, and it seemed to prevent an apparent 2.2% regression on a single-socket i7 box running 200 connections at saturation load.
1 parent 5713f03 commit 2201d80

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/backend/storage/ipc/procarray.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,14 +1759,26 @@ GetSnapshotData(Snapshot snapshot)
17591759
snapshot->regd_count = 0;
17601760
snapshot->copied = false;
17611761

1762-
/*
1763-
* Capture the current time and WAL stream location in case this snapshot
1764-
* becomes old enough to need to fall back on the special "old snapshot"
1765-
* logic.
1766-
*/
1767-
snapshot->lsn = GetXLogInsertRecPtr();
1768-
snapshot->whenTaken = GetSnapshotCurrentTimestamp();
1769-
MaintainOldSnapshotTimeMapping(snapshot->whenTaken, xmin);
1762+
if (old_snapshot_threshold < 0)
1763+
{
1764+
/*
1765+
* If not using "snapshot too old" feature, fill related fields with
1766+
* dummy values that don't require any locking.
1767+
*/
1768+
snapshot->lsn = InvalidXLogRecPtr;
1769+
snapshot->whenTaken = 0;
1770+
}
1771+
else
1772+
{
1773+
/*
1774+
* Capture the current time and WAL stream location in case this
1775+
* snapshot becomes old enough to need to fall back on the special
1776+
* "old snapshot" logic.
1777+
*/
1778+
snapshot->lsn = GetXLogInsertRecPtr();
1779+
snapshot->whenTaken = GetSnapshotCurrentTimestamp();
1780+
MaintainOldSnapshotTimeMapping(snapshot->whenTaken, xmin);
1781+
}
17701782

17711783
return snapshot;
17721784
}

0 commit comments

Comments
 (0)