Skip to content

Do less work in update-downloads #1372

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
Apr 27, 2018

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Apr 26, 2018

I was noticing that query to increment the downloads column on crates
was getting run way more than I'd expect it to be. I also was seeing
logs about a lock contention issue with that query. Specifically, those
logs pointed me at one of two things wrong here.

The first is that we were running this query even if we were
incrementing the value by 0. Second, we have our cutoff set to 2 days
ago. I think the reason for both of these is that we wanted to make sure
the processed column got set to true. We can pretty easily avoid this
by just setting it to true for all rows at the very end when all our
preconditions are met.

This doesn't necessarily fix the lock contention problem, but it does
result in hitting far fewer rows, which should alleviate the problem.

I was noticing that query to increment the downloads column on `crates`
was getting run way more than I'd expect it to be. I also was seeing
logs about a lock contention issue with that query. Specifically, those
logs pointed me at one of two things wrong here.

The first is that we were running this query even if we were
incrementing the value by 0. Second, we have our cutoff set to 2 days
ago. I think the reason for both of these is that we wanted to make sure
the `processed` column got set to true. We can pretty easily avoid this
by just setting it to true for all rows at the very end when all our
preconditions are met.

This doesn't necessarily fix the lock contention problem, but it does
result in hitting far fewer rows, which should alleviate the problem.
@sgrif sgrif requested a review from ashleygwilliams April 26, 2018 16:59
// against again.
diesel::update(version_downloads)
.set(processed.eq(true))
.filter(date.lt(diesel::dsl::date(now)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says older than 24 hours ago, but I read this more as "yesterday or older in UTC". The behavior itself seems fine to me, but the comment confused me a bit at first. (As you mentioned the old behavior was 2 days ago, so the comment was confusing then as well.)

Other than that, I'm r+. This logic seems clearer and more efficient now and I think I finally understand how this portion of the logic works!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, 24 hours is kinda wrong, but this matches what records will actually ever be touched again. After midnight UTC we never update old records.

@sgrif
Copy link
Contributor Author

sgrif commented Apr 27, 2018

bors: r+

bors-voyager bot added a commit that referenced this pull request Apr 27, 2018
1372: Do less work in update-downloads r=sgrif

I was noticing that query to increment the downloads column on `crates`
was getting run way more than I'd expect it to be. I also was seeing
logs about a lock contention issue with that query. Specifically, those
logs pointed me at one of two things wrong here.

The first is that we were running this query even if we were
incrementing the value by 0. Second, we have our cutoff set to 2 days
ago. I think the reason for both of these is that we wanted to make sure
the `processed` column got set to true. We can pretty easily avoid this
by just setting it to true for all rows at the very end when all our
preconditions are met.

This doesn't necessarily fix the lock contention problem, but it does
result in hitting far fewer rows, which should alleviate the problem.
@bors-voyager
Copy link
Contributor

bors-voyager bot commented Apr 27, 2018

Build succeeded

@bors-voyager bors-voyager bot merged commit ef04ab6 into rust-lang:master Apr 27, 2018
@sgrif sgrif deleted the sg-update-downloads-less branch April 27, 2018 13:33
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.

2 participants