large pipeline UI very slow

Summary

Pipeline view very slow to load with higher number of jobs.

Steps to reproduce

Create a pipeline with 200+ jobs and go to the pipeline view. For example: https://gitlab.com/jimbloemkolk_essent/test-ui-many-jobs/-/pipelines/1405421253

Example Project

https://gitlab.com/jimbloemkolk_essent/test-ui-many-jobs

What is the current bug behavior?

GraphQL query resulting in a multitude of Postgres queries. It looks like a N+1 issue where job queries are not properly batched. This was corroborated by Gitlab Professional services. @markdastmalchi-round @zmhiri

What is the expected correct behavior?

Proper batching and a fast graphql query / fast UI. This is especially relevant for customers with larger monorepos that run lot's of jobs per pipeline

Relevant logs and/or screenshots

Waterfall for 600 job pipeline on gitlab omnibus instance image

Waterfall for 400 job pipeline on gitlab.com (next) image

Relevant graphQL query

fragment CiNeeds on JobNeedUnion {
  ...CiBuildNeedFields
  ...CiJobNeedFields
  __typename
}
fragment CiBuildNeedFields on CiBuildNeed {
  id
  name
  __typename
}
fragment CiJobNeedFields on CiJob {
  id
  name
  __typename
}
fragment LinkedPipelineData on Pipeline {
  __typename
  id
  iid
  path
  cancelable
  retryable
  userPermissions {
    updatePipeline
    __typename
  }
  status: detailedStatus {
    __typename
    group
    label
    icon
    text
  }
  sourceJob {
    __typename
    id
    name
    retried
  }
  project {
    __typename
    id
    name
    fullPath
  }
}
query getPipelineDetails($projectPath: ID!, $iid: ID!) {
  project(fullPath: $projectPath) {
    __typename
    id
    pipeline(iid: $iid) {
      __typename
      id
      iid
      complete
      usesNeeds
      userPermissions {
        updatePipeline
        __typename
      }
      downstream {
        __typename
        nodes {
          ...LinkedPipelineData
          __typename
        }
      }
      upstream {
        ...LinkedPipelineData
        __typename
      }
      stages {
        __typename
        nodes {
          __typename
          id
          name
          status: detailedStatus {
            __typename
            action {
              __typename
              id
              icon
              path
              title
              confirmationMessage
            }
          }
          groups {
            __typename
            nodes {
              __typename
              id
              status: detailedStatus {
                __typename
                label
                group
                icon
                text
              }
              name
              size
              jobs {
                __typename
                nodes {
                  __typename
                  id
                  name
                  kind
                  scheduledAt
                  needs {
                    __typename
                    nodes {
                      __typename
                      id
                      name
                    }
                  }
                  previousStageJobsOrNeeds {
                    __typename
                    nodes {
                      ...CiNeeds
                      __typename
                    }
                  }
                  status: detailedStatus {
                    __typename
                    icon
                    tooltip
                    hasDetails
                    detailsPath
                    group
                    label
                    text
                    action {
                      __typename
                      id
                      buttonTitle
                      confirmationMessage
                      icon
                      path
                      title
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

This bug happens on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info

System information
System:		
Proxy:		no
Current User:	git
Using RVM:	no
Ruby Version:	3.1.4p223
Gem Version:	3.5.7
Bundler Version:2.5.8
Rake Version:	13.0.6
Redis Version:	7.0.15
Sidekiq Version:7.1.6
Go Version:	unknown

GitLab information
Version:	16.11.7-ee
Revision:	013d9311c68
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	PostgreSQL
DB Version:	14.12
URL:		https://-----
HTTP Clone URL:	https://-----/some-group/some-project.git
SSH Clone URL:	git@-----.:some-group/some-project.git
Elasticsearch:	no
Geo:		no
Using LDAP:	no
Using Omniauth:	yes
Omniauth Providers: azure_oauth2

GitLab Shell
Version:	14.35.0
Repository storages:
- default: 	unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path:		/opt/gitlab/embedded/service/gitlab-shell

Gitaly
- default Address: 	unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version: 	16.11.7
- default Git Version: 	2.43.5

Results of GitLab application Check

Expand for output related to the GitLab application check

Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 14.35.0 ? ... OK (14.35.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/4

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units) Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units) Projects have namespace: ... 1/4 ... yes (...) 6733/4643 ... yes Redis version >= 6.2.14? ... yes Ruby version >= 3.0.6 ? ... yes (3.1.4) Git user has default SSH configuration? ... yes Active users: ... 592 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-8.x or OpenSearch version 1.x ... skipped (Advanced Search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Edited by Jim Bloemkolk