Backend: Add cached denormalized count of jobs - GraphQL
Problem
The example query below blows up with an Internal Server Error
.
This is due to the count field on the CiJobConnection type. That field works fine for projects with low job records but when they are larger the query blows up with an Internal server error.
This prevents rollout of the new jobs table filtered search. [jobs_table_vue] Rollout Plan (#327500 - closed)
{
project(fullPath: "gitlab-org/gitlab") {
jobs {
count
}
}
}
Potential Solution
Suggestion from @alexkalderimis in the #f_graphql
channel for a solution.
We probably need a cached denormalized count of jobs (like we have for some other records), if throwing indices at the problem does not solve things. For example we do this with the open MR count on projects
Or add a limited count field: #360672 (comment 941308255)
Designs
- Show closed items
Blocks
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- Payton Burdette marked this issue as related to #356007 (closed)
marked this issue as related to #356007 (closed)
- Payton Burdette marked this issue as related to #327500 (closed)
marked this issue as related to #327500 (closed)
- Sam Beckham added bugperformance label
added bugperformance label
- Developer
Labelling this severity1 as-per the handbook severity guides https://about.gitlab.com/handbook/engineering/quality/issue-triage/#severity. On large enough projects (like GitLab) this definitely falls into the 9000ms+ category.
cc @marknuzzo
Edited by Sam Beckham Collapse replies - Contributor
@samdbeckham @pburdette added to the next milestone as we don't look to have room with other VerifyP1 and VerifyP2 issues in the current milestone. let's move the rollout issues there and block them on this issue too.
- Author Maintainer
@jheimbuck_gl issues have been updated! Thanks
1 - Contributor
Thanks everyone - I updated the labeling so this will show up in our needs weight board to be weighted next week too.
- Developer
- Sam Beckham added severity1 label
added severity1 label
- James Heimbuck changed milestone to %15.1
changed milestone to %15.1
- James Heimbuck added VerifyP2 label
added VerifyP2 label
- James Heimbuck changed the description
Compare with previous version changed the description
- James Heimbuck added priority1 label
added priority1 label
- Mark Nuzzo changed title from Add cached denormalized count of jobs - GraphQL to Backend: Add cached denormalized count of jobs - GraphQL
changed title from Add cached denormalized count of jobs - GraphQL to Backend: Add cached denormalized count of jobs - GraphQL
- Mark Nuzzo added needs weight label
added needs weight label
- 🤖 GitLab Bot 🤖 added sectionops label
added sectionops label
- 🤖 GitLab Bot 🤖 added [deprecated] Accepting merge requests label
added [deprecated] Accepting merge requests label
- Payton Burdette mentioned in issue #356007 (closed)
mentioned in issue #356007 (closed)
- James Heimbuck mentioned in issue gitlab-org/ci-cd/pipeline-execution#98 (closed)
mentioned in issue gitlab-org/ci-cd/pipeline-execution#98 (closed)
- Maintainer
I see that the
count
attribute is defined byTypes::CountableConnectionType
. Maybe we could define a limited count method as well:diff --git a/app/graphql/types/countable_connection_type.rb b/app/graphql/types/countable_connection_type.rb index 0f24964daa6..5b01663cfc0 100644 --- a/app/graphql/types/countable_connection_type.rb +++ b/app/graphql/types/countable_connection_type.rb @@ -6,6 +6,9 @@ class CountableConnectionType < GraphQL::Types::Relay::BaseConnection field :count, GraphQL::Types::Int, null: false, description: 'Total count of collection.' + field :count_with_limit, GraphQL::Types::Int, null: false, + description: 'Total count of collection.' + def count # rubocop: disable CodeReuse/ActiveRecord relation = object.items @@ -20,5 +23,20 @@ def count relation.size end end + + def count_with_limit + # rubocop: disable CodeReuse/ActiveRecord + relation = object.items + + # sometimes relation is an Array + relation = relation.reorder(nil) if relation.respond_to?(:reorder) + # rubocop: enable CodeReuse/ActiveRecord + + if relation.try(:group_values)&.present? + relation.size.keys.size + else + relation.page.total_count_with_limit(:all, limit: 1000) + end + end end end
@pburdette wdyt?
Collapse replies - Author Maintainer
@mbobin Given it's defined on
countable_connection_type
that would be a smooth refactor for us. I guess my only concern would be just having access tocount
and others not knowing it's potential to throw an internal server error. Maybe we just change the docs on the field? Could be as simple as that?EDIT: But yes
countWithLimit
would work for us.Edited by Payton Burdette - Maintainer
Any network call has the potential to throw an internal server error, but this one is more likely because it's easier to have database timeouts on count queries.
Maybe we just change the docs on the field? Could be as simple as that?
Maybe we should not expose counts in this case since it'll most likely time out.
- Author Maintainer
Any network call has the potential to throw an internal server error, but this one is more likely because it's easier to have database timeouts on count queries
Right, my point exactly.
Maybe we should not expose counts in this case since it'll most likely time out
That's fine with me. It works fine on small pipelines with low counts. But I guess we don't have to solve this immediately on this issue, we could create a new one.
- Contributor
@pburdette @mbobin could you make sure you're happy with the proposal and move this to workflowready for development if it is ready for that please?
cc @marknuzzo
- Author Maintainer
@jheimbuck_gl yep the proposals look good. Moved to workflowready for development
1 1 1
- Marius Bobin set weight to 2
set weight to 2
- Marius Bobin removed needs weight label
removed needs weight label
- Marius Bobin changed the description
Compare with previous version changed the description
- James Heimbuck added workflowplanning breakdown label
added workflowplanning breakdown label
- James Heimbuck added Stretch label
added Stretch label
- Payton Burdette added workflowready for development label and removed workflowplanning breakdown label
added workflowready for development label and removed workflowplanning breakdown label
- 🤖 GitLab Bot 🤖 added SLOMissed label
added SLOMissed label
- Marius Bobin added workflowin dev label and removed workflowready for development label
added workflowin dev label and removed workflowready for development label
- Marius Bobin assigned to @mbobin
assigned to @mbobin
- Marius Bobin mentioned in merge request !89642 (merged)
mentioned in merge request !89642 (merged)
- Maintainer
Thanks for working on this @mbobin! We've removed the Seeking community contributions label to avoid having multiple people working on the same issue.
- 🤖 GitLab Bot 🤖 removed [deprecated] Accepting merge requests label
removed [deprecated] Accepting merge requests label
- Sam Beckham mentioned in issue verify-stage#206 (closed)
mentioned in issue verify-stage#206 (closed)
- James Heimbuck mentioned in issue gitlab-org/ci-cd/pipeline-execution#101 (closed)
mentioned in issue gitlab-org/ci-cd/pipeline-execution#101 (closed)
- Marius Bobin added workflowin review label and removed workflowin dev label
added workflowin review label and removed workflowin dev label
- Marius Bobin mentioned in commit 94daf8cf
mentioned in commit 94daf8cf
- Marius Bobin added workflowverification label and removed workflowin review label
added workflowverification label and removed workflowin review label
- Maintainer
@pburdette @samdbeckham !89642 (merged) was merged a couple of hours ago.
Collapse replies - Developer
Excellent news. Thanks @mbobin
@pburdette is there any frontend work to be done to start using this or can we proceed with the rollout?
- Author Maintainer
is there any frontend work to be done to start using this or can we proceed with the rollout?
Yes we will need to refactor to use the new count.
- Author Maintainer
@samdbeckham actually maybe not. I just took a loot at the MR @mbobin opened and it looks like there is a default count value of
1000
for the code so we might not need any changes after all. - Maintainer
@pburdette yeah, but if the count is greater than
1000
it will return a capped count of1001
, so it might need some UX changes to show1001
as1000+
. - Author Maintainer
@mbobin ahh yeah good point!!!
- Author Maintainer
MR opened here !90833 (merged)
2 1
- Marius Bobin closed
closed
- Marius Bobin added workflowproduction label and removed workflowverification label
added workflowproduction label and removed workflowverification label
- Miguel Rincon mentioned in issue #327500 (closed)
mentioned in issue #327500 (closed)