Skip to main content

SpinDelay

Short Description

SpinDelay tracks delays caused by spinlocks that are in a "sleep" state.

Detailed Description​

SpinDelay was added in PostgreSQL 16 to report and track delays caused by spinlocks that are in a "sleep" state.

In PostgreSQL, SpinDelay is used in its spinlock implementation. Spinlocks are lightweight locks used to protect small critical sections in shared memory. PostgreSQL’s s_lock.c includes spinlock code where the SpinDelay is applied. This mechanism helps to:

  • Avoid excessive CPU consumption during spinlock contention.
  • Provide fairer access to locks in highly concurrent environments by introducing small delays between retries.

Trade-offs

  • Pro: For short waits, it can significantly reduce latency compared to blocking.
  • Con: For long waits, spinning wastes CPU cycles and can degrade overall system performance. Systems must carefully balance spin-waiting and yielding/blocking.

Search online​

If this article doesn't have the information you need you can try searching online. Remember, you can contribute suggestions to this page.