go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.65k stars 5.46k forks source link

big PR view details is extremely slow #31896

Open phoedos opened 2 months ago

phoedos commented 2 months ago

Description

Faced with long-time gitea work during view details of big PR

http://giteaurl/MYORG/myrepo/pulls/68/files

dev #68
Merged
myuser merged 13 commits from dev  into dev_adaptive yesterday
Conversation
0
Commits
13
Files Changed
58
+1701 -284

58 changed files
with
1701 additions
and
284 deletions

Powered by Gitea
Version:
1.22.1
Page:
360658ms
Template:
559ms

this request took up to 360(!) seconds to display page

docker logs gitea:

2024/08/21 00:13:16 ...eb/routing/logger.go:68:func1() [W] router: slow      GET /MYORG/myrepo/pulls/68/files for 10.10.2.100:0, elapsed 3209.6ms @ repo/pull.go:900(repo.ViewPullFilesForAllCommitsOfPr)
2024/08/21 00:19:15 ...eb/routing/logger.go:102:func1() [I] router: completed GET /MYORG/myrepo/pulls/68/files for 10.10.2.100:0, 200 OK in 360658.2ms @ repo/pull.go:900(repo.ViewPullFilesForAllCommitsOfPr)

tried made changes to indexer_type bleve->db->elasticsearch: no improvements tried to enable Postgresql query timing: no queries with latency >100ms. 99% of gitea queries hit in <10ms responce.

Issue reproduce stable on server/local environment (SSD/nVME m2 drives), typical hdparm from drive where gitea folder is mounted:

hdparm -tT  /dev/sdb
/dev/sdb:
 Timing cached reads:   40268 MB in  2.00 seconds = 20169.03 MB/sec
 Timing buffered disk reads: 4640 MB in  3.00 seconds = 1546.34 MB/sec

docker-compose.yml example

services:
  gitea:
    image: gitea/gitea:1.22.1
    container_name: gitea
    restart: unless-stopped
    environment:
      USER_UID: 1000
      USER_GID: 1000
      #database connection
      GITEA__database__DB_TYPE: postgres
      GITEA__database__HOST: db:5432
      GITEA__database__NAME: gitea
      GITEA__database__USER: gitea
      GITEA__database__PASSWD: gitea
      #domain, rooturl, server settings
      GITEA__server__APP_DATA_PATH: /data/gitea
      GITEA__server__HTTP_PORT: 8080
      GITEA__server__DOMAIN: localhost
      GITEA__server__ROOT_URL: http://127.0.0.1:8080
      #indexer
      GITEA__indexer__ISSUE_INDEXER_TYPE: 'elasticsearch'
      GITEA__indexer__ISSUE_INDEXER_CONN_STR: 'http://elastic:password@es:9200'
      GITEA__indexer__ISSUE_INDEXER_NAME: 'gitea_issues'
      GITEA__indexer__REPO_INDEXER_ENABLED: true
      GITEA__indexer__REPO_INDEXER_REPO_TYPES: 'sources'
      GITEA__indexer__REPO_INDEXER_TYPE: 'elasticsearch'
      GITEA__indexer__REPO_INDEXER_CONN_STR: 'http://elastic:password@es:9200'
      GITEA__indexer__REPO_INDEXER_NAME: 'gitea_codes'
    networks:
      - gitea
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 8080:8080
    depends_on:
       db:
         condition: service_healthy
       es:
         condition: service_healthy

  db:
    image: postgres:16.3
    restart: unless-stopped
    environment:
      POSTGRES_USER: gitea
      POSTGRES_PASSWORD: gitea
      POSTGRES_DB: gitea
    networks:
      - gitea
    volumes:
      - ./postgres16:/var/lib/postgresql/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    healthcheck :
      test: [ "CMD", "pg_isready", "-q", "-d", "gitea", "-U", "gitea" ]
      interval : 5s
      timeout : 5s
      retries : 5

  es:
    image: elasticsearch:8.14.2
    environment:
      - node.name=es
      - cluster.name=gitea
      - discovery.type=single-node
      - ELASTIC_PASSWORD=password
      - xpack.security.enabled=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    networks:
      - gitea
    volumes:
      - ./esdata:/usr/share/elasticsearch/data
    healthcheck:
      test: ["CMD", "curl", "-s", "http://elastic:passwors@es:9200"]
      interval: 30s
      timeout: 10s
      retries: 5

networks:
 gitea:

Gitea Version

1.22.1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

docker-compose

Database

PostgreSQL

jpraet commented 4 days ago

Same issue here after upgrading from Gitea 1.21.8 to 1.22.3.

2024/10/16 08:42:52 ...eb/routing/logger.go:68:func1() [W] router: slow GET /CBSS/ssh-communication-trace/pulls/52/files for 172.19.0.2:34192, elapsed 3014.0ms @ repo/pull.go:900(repo.ViewPullFilesForAllCommitsOfPr) 2024/10/16 08:44:19 ...ers/web/repo/pull.go:746:viewPullFiles() [E] SyncAndGetUserSpecificDiff: context canceled 2024/10/16 08:44:19 ...eb/routing/logger.go:102:func1() [I] router: completed GET /CBSS/ssh-communication-trace/pulls/52/files for 172.19.0.2:34192, 500 Internal Server Error in 90007.3ms @ repo/pull.go:900(repo.ViewPullFilesForAllCommitsOfPr)

(It stops after 90 seconds because HAProxy timeout)

The PR isn't even very big (7 changed files with 1005 additions and 219 deletions).

What's also strange is that on some occasions the same page does respond quickly (Page: 1504ms Template: 1103ms).

Database: PostgreSQL 14