Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor locking tweaks to reduce contention #647

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

rohanpm
Copy link
Member

@rohanpm rohanpm commented Dec 12, 2023

A couple of places where a Publish was locked FOR UPDATE can safely use shared locks rather than exclusive locks:

  • when adding publish items, we want to lock the Publish to ensure it remains in PENDING state during our update. But we won't actually change the state of the Publish, so we only need a read/shared lock.

  • similarly during commit, we want to lock the Publish to ensure it's in PENDING state. In phase2 commit, we actually then update the state of the Publish, so we need an exclusive lock. In phase1 commit we don't modify the Publish and it's safe to use a read/shared lock.

When using the postgresql dialect, "read=True" here maps to "FOR SHARE" which is documented at [1].

This change is meant to improve performance by eliminating some scenarios where a request would have had to wait to obtain an exclusive lock on the publish; mainly during Pulp publish of many repos, where many update and phase1 commit requests will be happening concurrently for the same publish.

[1] https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-ROWS

A couple of places where a Publish was locked FOR UPDATE can safely use
shared locks rather than exclusive locks:

- when adding publish items, we want to lock the Publish to ensure
  it remains in PENDING state during our update. But we won't actually
  change the state of the Publish, so we only need a read/shared lock.

- similarly during commit, we want to lock the Publish to ensure it's in
  PENDING state. In phase2 commit, we actually then update the state of
  the Publish, so we need an exclusive lock. In phase1 commit we don't
  modify the Publish and it's safe to use a read/shared lock.

When using the postgresql dialect, "read=True" here maps to "FOR SHARE"
which is documented at [1].

This change is meant to improve performance by eliminating some
scenarios where a request would have had to wait to obtain an exclusive
lock on the publish; mainly during Pulp publish of many repos, where
many update and phase1 commit requests will be happening concurrently
for the same publish.

[1] https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-ROWS
@rohanpm rohanpm marked this pull request as ready for review December 12, 2023 03:22
@rohanpm rohanpm merged commit 8fd2df5 into release-engineering:master Dec 12, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants