Skip to content
StackDecode
System Design
16. Performance EngineeringAnimated

Lock Contention

Threads waiting on the same lock.

The idea

Many threads fighting for a lock slow everything down.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

Txn 1Row ARow BTxn 2lock A
  • current message
  • earlier
  • failure or attack

Txn 1 locks row A.

step:
1/6
from:
Txn 1
to:
Row A
1/6

Time runs downward. Solid arrows are requests, dashed arrows are replies.

Step by step

  1. 1Many threads request a lock
  2. 2One holds it
  3. 3Others wait
  4. 4Throughput drops

Where it is used

Concurrent systems.

Watch out for

Use finer locks, lock-free structures or fewer shared writes.

Related