Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,761
    • Issues 44,761
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,329
    • Merge requests 1,329
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #31031
Closed
Open
Issue created Aug 18, 2019 by Stan Hu@stanhuOwner

Gitaly N+1 queries in /api/:version/groups/:id

As seen in #mech_symp_alerts (https://log.gitlab.net/goto/0ed2e7715e9456c3bafbe9f63b5d5559), there are some queries that are reguarly taking over 500 Gitaly calls.

I can reproduce this by stubbing out RequestStore::Middleware, and then calling:

user = User.find_by(username: 'stanhu')
RequestStore.begin!
RequestStore[:peek_enabled] = true
Gitlab::Profiler.with_user(user) { app.get '/api/v4/groups/issue%2Dreproduce' }   
[ gprd ] production> Gitlab::SafeRequestStore['gitaly_call_details'].count
=> 557
[ gprd ] production> Gitlab::SafeRequestStore['gitaly_call_details'].each_with_object(Hash.new(0)) { |e, h| h[e[:feature]] += 1 }
=> {"ref_service#find_default_branch_name"=>557}

Proposal

It looks like the issue is that the list of groups is paginated, but the list of projects within the group is NOT. I think we need to consider splitting the projects of a group into a separate endpoint that can be paginated (e.g. /api/:version/groups/:id/projects).

There is already a separate endpoint to get all of a group's projects (https://docs.gitlab.com/ee/api/groups.html#list-a-groups-projects) so restricting this endpoint to return a maximum of 100 projects seems a sensible first step to mitigate the problem (and prevent abuse).

Edited Nov 18, 2019 by Jeremy Watson (ex-GitLab)
Assignee
Assign to
Time tracking