Skip to content

Update version_downloads.counted last to minimize lock contention #2154

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

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

jtgeibel
Copy link
Member

If we defer the update to version_downloads.counted until immediately
before the commit, it should eliminate the contention between counting
new downloads and propagating previous downloads.

Refs: #2153
See also: #2153 (comment)

If we defer the update to `version_downloads.counted` until immediately
before the commit, it should eliminate the contention between counting
new downloads and propagating previous downloads.

Refs: rust-lang#2153
See also: rust-lang#2153 (comment)
@rust-highfive
Copy link

r? @carols10cents

(rust_highfive has picked a reviewer for you, use r? to override)

@jtgeibel
Copy link
Member Author

Lets do r? @sgrif

@rust-highfive rust-highfive assigned sgrif and unassigned carols10cents Jan 23, 2020
@jtgeibel
Copy link
Member Author

I expect this PR will completely eliminate the occurrence of slow download requests. Here's a timeline showing the progress so far:

  • 14th - switched to performance dynos
  • 15th - 49 slow downloads
  • 16th - 56 slow downloads
  • 17th - 117 slow downloads
  • 18th - moved some expensive queries to the read-only replica; 5 slow downloads (2 before, 3 after)
  • 19th - 9 slow downloads
  • 20th - 3 slow downloads
  • 21st - 2 slow downloads
  • 22nd - 7 slow downloads
  • 23rd - 1 slow downloads
  • 24th - 1 slow downloads
  • 25th - 2 today so far

@sgrif
Copy link
Contributor

sgrif commented Jan 28, 2020

I'd be really surprised that this was specifically causing lock contention, since the database will log any locks that are held for long enough to cause a slow request.

That said, this change seems completely reasonable on its own

@jtgeibel
Copy link
Member Author

I'd be really surprised that this was specifically causing lock contention, since the database will log any locks that are held for long enough to cause a slow request.

The example I found in the logs from the 19th (#2153 (comment)) seem to be the only occurrence of the database complaining about this loudly. Postges appears to have a 1 second threshold for generating log output about slow locks. Searching the logs for program:app/postgres waiting shows a few other interesting bits of log output:

  • program:app/postgres.7060, program:app/postgres.11521, and program:app/postgres.5638 - slow at inserting into version_downloads
  • program:app/postgres.10814 - slow at inserting into emails 😕
  • program:app/postgres.19904 - several interesting messages at once, but this appears to align with a deploy so maybe a migration locked something for a moment.

Overall, the events logged here are far fewer than the number of slow download requests we've observed. The only explanation I have for that at the moment is that the download endpoint also issues a query joining versions and crates. Maybe slow requests end up spending some extra time in each query, but not enough to log either query as >1 second by postgres.

@sgrif
Copy link
Contributor

sgrif commented Jan 28, 2020 via email

@jtgeibel
Copy link
Member Author

I should be able to deploy this shortly.

@bors r=sgrif

@bors
Copy link
Contributor

bors commented Jan 29, 2020

📌 Commit 97e9997 has been approved by sgrif

@bors
Copy link
Contributor

bors commented Jan 29, 2020

⌛ Testing commit 97e9997 with merge fb925f9...

bors added a commit that referenced this pull request Jan 29, 2020
Update `version_downloads.counted` last to minimize lock contention

If we defer the update to `version_downloads.counted` until immediately
before the commit, it should eliminate the contention between counting
new downloads and propagating previous downloads.

Refs: #2153
See also: #2153 (comment)
@bors
Copy link
Contributor

bors commented Jan 29, 2020

☀️ Test successful - checks-travis
Approved by: sgrif
Pushing fb925f9 to master...

@bors bors merged commit 97e9997 into rust-lang:master Jan 29, 2020
@jtgeibel jtgeibel deleted the prod/reduce-dl-count-contention branch January 30, 2020 00:00
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.

5 participants