About a month ago, I told Kevin Grittner in an off-list conversation
that I'd work on providing him with some statistics about lwlock
contention under SSI. I then ran a benchmark on a 16-core,
64-hardware thread IBM server, testing read-only pgbench performance
at scale factor 300 with 1, 8, and 32 clients (and an equal number of
client threads). The following non-default configuration settings
were used:
shared_buffers = 8GB
maintenance_work_mem = 1GB
synchronous_commit = off
checkpoint_segments = 300
checkpoint_timeout = 15min
checkpoint_completion_target = 0.9
log_line_prefix = '%t [%p] '
default_transaction_isolation = 'serializable'
max_pred_locks_per_transaction = 1000
After running the test, I dropped the ball for a month. But, picking
it back up again, here are the results. I've taken the data that is
produced by LWLOCK_STATS, and I've filtered it down by consolidating
entries for the same lock across all PIDs that show up in the log
file. Then, I've omitted all entries where blk == 0 and spindelay ==
0, because those locks were never contended, so they're boring; and
also because including them makes the results too long to make sense
of. The results for the remaining locks are attached as three files,
based on the number of clients. The really revealing entries, IMHO,
are these results from the 32-client test:
lwlock 28: shacq 86952211 exacq 257812441 blk 35212093 spindelay 40811
lwlock 29: shacq 0 exacq 87516792 blk 31177203 spindelay 10038
lwlock 30: shacq 227960353 exacq 0 blk 0 spindelay 10711
These locks are all SSI-related and they're all really hot. Lock 28
is SerializableXactHashLock and lock 29 is
SerializableFinishedListLock; both are acquired an order of magnitude
more often than any non-SSI lock, and cause two orders of magnitude
more blocking than any other lock whatsoever. Lock 30 is
SerializablePredicateLockListLock, which has no exclusive lock
acquisitions at all on this test, but the shared acquisitions result
in significant spinlock contention. This latter problem could
probably be ameliorated with a reader/writer lock (a primitive we
don't currently have in Postgres, but you could build one up using
lwlocks), but it's unlikely to make much difference without doing
something about SerializableXactHashLock and
SerializableFinishedListLock first.
Once you get past these big three, there's also a ton of blocking on
the PredicateLockMgrLocks, which seem only ever to be acquired in
exclusive mode, but it's not nearly as bad due to the 16-way
partitioning.
[Obligatory disclaimer: This has nothing to do with 9.3 and is not
intended to distract attention therefrom.]
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
lwlock 0: shacq 0 exacq 1716121 blk 49 spindelay 0
lwlock 44: shacq 8834024 exacq 106905 blk 1 spindelay 0
lwlock 46: shacq 1360967 exacq 107745 blk 1 spindelay 0
lwlock 0: shacq 0 exacq 1724700 blk 31636 spindelay 9
lwlock 4: shacq 48837488 exacq 129 blk 2 spindelay 0
lwlock 28: shacq 59034372 exacq 205443978 blk 12204797 spindelay 1022
lwlock 29: shacq 0 exacq 59096784 blk 4817845 spindelay 66
lwlock 30: shacq 196048118 exacq 0 blk 0 spindelay 318
lwlock 33: shacq 9590676 exacq 107818 blk 1409 spindelay 3
lwlock 34: shacq 9318919 exacq 107241 blk 1342 spindelay 0
lwlock 35: shacq 8092746 exacq 106793 blk 1235 spindelay 0
lwlock 36: shacq 9864538 exacq 108249 blk 1499 spindelay 0
lwlock 37: shacq 57488133 exacq 106358 blk 5323 spindelay 58
lwlock 38: shacq 9704085 exacq 108118 blk 1449 spindelay 0
lwlock 39: shacq 10340396 exacq 107910 blk 1524 spindelay 2
lwlock 40: shacq 8163154 exacq 108542 blk 1299 spindelay 3
lwlock 41: shacq 8324565 exacq 107888 blk 1269 spindelay 2
lwlock 42: shacq 9752315 exacq 108333 blk 1432 spindelay 0
lwlock 43: shacq 9066090 exacq 107348 blk 1429 spindelay 0
lwlock 44: shacq 59938209 exacq 107609 blk 6492 spindelay 64
lwlock 45: shacq 7628029 exacq 106633 blk 1117 spindelay 4
lwlock 46: shacq 9211130 exacq 108452 blk 1312 spindelay 1
lwlock 47: shacq 9851329 exacq 107981 blk 1448 spindelay 1
lwlock 48: shacq 8129228 exacq 107463 blk 1262 spindelay 0
lwlock 49: shacq 0 exacq 90 blk 2 spindelay 0
lwlock 50: shacq 0 exacq 288 blk 13 spindelay 2
lwlock 51: shacq 0 exacq 138 blk 2 spindelay 0
lwlock 53: shacq 0 exacq 126 blk 3 spindelay 0
lwlock 59: shacq 0 exacq 1080 blk 14 spindelay 0
lwlock 61: shacq 0 exacq 192 blk 4 spindelay 0
lwlock 63: shacq 0 exacq 480 blk 10 spindelay 0
lwlock 65: shacq 0 exacq 13472461 blk 58249 spindelay 2
lwlock 66: shacq 0 exacq 13554792 blk 59318 spindelay 1
lwlock 67: shacq 0 exacq 13347513 blk 57087 spindelay 1
lwlock 68: shacq 0 exacq 13458882 blk 60748 spindelay 0
lwlock 69: shacq 0 exacq 13457110 blk 60654 spindelay 2
lwlock 70: shacq 0 exacq 13592353 blk 61859 spindelay 1
lwlock 71: shacq 0 exacq 13546043 blk 61450 spindelay 2
lwlock 72: shacq 0 exacq 13375547 blk 59844 spindelay 1
lwlock 73: shacq 0 exacq 13492622 blk 61400 spindelay 0
lwlock 74: shacq 0