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

api: Fix index usage for usage queries #2002

Merged
merged 1 commit into from
Dec 22, 2023
Merged

Conversation

victorges
Copy link
Member

What does this pull request do? Explain your changes. (required)

This is to fix the usage queries that have been causing a 20% CPU sustained spike on our DB
for 10 minutes every hour.

This is caused by the way we are filtering by the createdAt timestamp, which is not able to use
the existing index on that field since the index is created on the string value, not a number. The fix
was to also query by the string value, which should be fine since timestamps have the same number
of digits until 2286.

We should eventually fix our indexes to optimize for number queries as well, since this is not the
only place where we filter by numbers, but that would be a more complex change that I don't think
is worth to do as an emergency measure while we have a lot of traffic from fishtank right now.

Specific updates (required)

  • Filter by the createdAt field as a string instead of bigint

How did you test each of these updates (required)
Ran the query manually on pgAdmin and ensured the index would be used.

Does this pull request close any open issues?
CPU spikes on DB.

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@victorges victorges requested a review from a team as a code owner December 22, 2023 15:20
Copy link

vercel bot commented Dec 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
livepeer-studio ✅ Ready (Inspect) Visit Preview Dec 22, 2023 3:20pm

@victorges victorges merged commit 16fd709 into master Dec 22, 2023
12 checks passed
@victorges victorges deleted the vg/fix/usage-query-index branch December 22, 2023 20:15
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