Amazon-Web-Services

Gitlab:Git 操作在 EC2 上非常慢

  • May 3, 2019

編輯:事實證明這是一個 Gitlab 問題,但是我仍然沒有解決方案。

我的兩個 AWS EC2 實例出現了奇怪的情況。它們在作業系統、區域和實例類型(均為 t3.micro)方面完全相同,以相同的方式設置(但是,第一個是幾個月前設置的)。

兩者都存在於 eu-central-1c 可用區,並且都在同一個 git 儲存庫上執行。兩者都是最新的(CentOS 7.6.1810)。

舊伺服器:

$ time git pull
Already up-to-date.

real    0m0.306s
user    0m0.034s
sys     0m0.016s

較新的伺服器:

$ time git pull
Already up-to-date.

real    2m7.547s
user    0m0.026s
sys     0m0.024s

它也始終需要大約 2 分 7 秒。

還:

舊伺服器:

--2019-04-09 10:52:03--  https://speed.hetzner.de/1GB.bin
Resolving speed.hetzner.de (speed.hetzner.de)... 88.198.248.254, 2a01:4f8:0:59ed::2
Connecting to speed.hetzner.de (speed.hetzner.de)|88.198.248.254|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1048576000 (1000M) [application/octet-stream]
Saving to: ‘1GB.bin’

100%[===============================================================>] 1,048,576,000  121MB/s   in 6.5s   

2019-04-09 10:52:10 (154 MB/s) - ‘1GB.bin’ saved [1048576000/1048576000]

較新的伺服器:

--2019-04-09 10:54:04--  https://speed.hetzner.de/1GB.bin
Resolving speed.hetzner.de (speed.hetzner.de)... 88.198.248.254, 2a01:4f8:0:59ed::2
Connecting to speed.hetzner.de (speed.hetzner.de)|88.198.248.254|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1048576000 (1000M) [application/octet-stream]
Saving to: ‘1GB.bin’

100%[===============================================================>] 1,048,576,000  130MB/s   in 5.9s   

2019-04-09 10:54:10 (170 MB/s) - ‘1GB.bin’ saved [1048576000/1048576000]

編輯:我嘗試使用 GitHub 儲存庫而不是我們的 GitLab,結果似乎是 GitLab 問題。什麼可能導致 GitLab 快速響應舊伺服器而不響應另一台伺服器?

編輯 2:嘗試通過 HTTPS 進行複製。詢問我的使用者名需要 2 分鐘。

此外,通過 SSH 的詳細輸出:

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git pull
trace: exec: 'git-pull'
trace: run_command: 'git-pull'
trace: built-in: git 'rev-parse' '--git-dir'
trace: built-in: git 'rev-parse' '--is-bare-repository'
trace: built-in: git 'rev-parse' '--show-toplevel'
trace: built-in: git 'ls-files' '-u'
trace: built-in: git 'symbolic-ref' '-q' 'HEAD'
trace: built-in: git 'config' '--bool' 'branch.#hidden#.rebase'
trace: built-in: git 'config' '--bool' 'pull.rebase'
trace: built-in: git 'rev-parse' '-q' '--verify' 'HEAD'
trace: built-in: git 'fetch' '--update-head-ok'
trace: run_command: 'ssh' '-p' '#hidden#' 'git@#hidden.tld#' 'git-upload-pack '\''/#hidden#/#hidden#.git'\'''

使用詳細輸出發現問題。

較新的伺服器嘗試使用 IPv6 聯繫 git 端點伺服器,並等待超時,然後再回退到 IPv4(這實際上有效)。

$ GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone https://#hidden#/#hidden#/#hidden#.git
trace: built-in: git 'clone' 'https://#hidden#/#hidden#/#hidden#.git'
Cloning into '#hidden#'...
trace: run_command: 'git-remote-https' 'origin' 'https://#hidden#/#hidden#/#hidden#.git'
* Couldn't find host #hidden# in the .netrc file; using defaults
* About to connect() to #hidden# port 443 (#0)
*   Trying x:x:x:x:x:x:x:x...
* Connection timed out
*   Trying x.x.x.x...

引用自:https://serverfault.com/questions/962194