This issue has been fixed by Google which introduced a version 2 git protocol aiming at solving that exact same issue. See below T103990#6268632
I found out my git fetch on operations/puppet.git is slightly too slow:
Over ssh that is 40 seconds:
$ time git fetch ssh://hashar@gerrit.wikimedia.org:29418/operations/puppet.git From ssh://gerrit.wikimedia.org:29418/operations/puppet * branch HEAD -> FETCH_HEAD real 0m39.609s user 0m0.176s sys 0m0.219s
Over https 20 seconds:
$ time git fetch https://gerrit.wikimedia.org/r/p/operations/puppet.git From https://gerrit.wikimedia.org/r/p/operations/puppet * branch HEAD -> FETCH_HEAD real 0m19.165s user 0m0.438s sys 0m0.120s
It is network bound. Using git debug env variables GIT_TRACE and GIT_TRACE_PACKET, git-fetch executes git upload-pack on Gerrit server which yields ALL references including refs/changes/*. That looks like:
$ GIT_TRACE=1 GIT_TRACE_PACKET=1 git fetch 2>&1| head -n25 trace: built-in: git 'fetch' trace: run_command: 'ssh' '-p' '29418' 'hashar@gerrit.wikimedia.org' 'git-upload-pack '\''/operations/puppet.git'\''' packet: fetch< 874c4155a4f831a2331b9f6cb8c2ac806c03f603 HEAD\0 include-tag multi_ack_detailed multi_ack ofs-delta side-band side-band-64k thin-pack no-progress shallow packet: fetch< 9126e0b refs/cache-automerge/01/7f9d81411d3a534d7868cd251bc5d04a00524a packet: fetch< 48d1474 refs/cache-automerge/01/b66390dd5f6df1bc245971482f43dd59dfcd4f packet: fetch< c8bbf14 refs/cache-automerge/02/84485a2b85cc49d46166bedea485e8716f4034 packet: fetch< 32066cb refs/cache-automerge/03/ad7228e9bd88c7526893791499ea068a7fcf32 packet: fetch< 6eb986b refs/cache-automerge/05/e646c89fdc620fb2757775c2a5e9a7b6031a8d packet: fetch< 4b825dc refs/cache-automerge/08/17d532d8576761eb14087332a343c7e86ec937 packet: fetch< 4b825dc refs/cache-automerge/08/218590a6fe5590ee1e3a3189618b04daf40692 packet: fetch< 0a6d437 refs/cache-automerge/0a/7b3958b1f6aeab72b8fe766bcde6bc245b9d08 packet: fetch< 3cef6ee refs/cache-automerge/0a/faf2dcd52226091daa0ac503dab15186338cf1 packet: fetch< 127c9fa refs/cache-automerge/10/0e2dc523f8721d28f1b57de40c111dea442ccd packet: fetch< e40a942 refs/cache-automerge/12/0ff0a8ec28981ea82fa824253f58cfd1a9f466 packet: fetch< c6dea31 refs/cache-automerge/12/c00202d713973ebf1a567f969b710b03d1711b packet: fetch< 14c2007 refs/cache-automerge/17/2866932fda4cce417aca2ddf72b62386e095f5 packet: fetch< 9126e0b refs/cache-automerge/1e/ad36f47754cd0e2788a48573451f54553c7612 packet: fetch< c48b56a refs/cache-automerge/23/f2299e57e144409fa120d82c69b0c7040dbca7 packet: fetch< 9126e0b refs/cache-automerge/24/ba68d86933de429a330eff4eae018dc71140de packet: fetch< 5790b5b refs/cache-automerge/26/ac09999377a12f0e4d69f09dfe37b4b3342db4 packet: fetch< 22e5a3a refs/cache-automerge/2a/387f4a1fff03e9500ec8186f269e083907e8d4 packet: fetch< 4596d1f refs/cache-automerge/2e/3ad288bd263792ab2980c60c68cb47fe01bfb1 packet: fetch< efc147b refs/cache-automerge/2e/f5d586e86a7dd4e06e7c54e77753dd101476db packet: fetch< 69afa3b refs/cache-automerge/33/77e76f8918d76ba014811e941e20e048879c3d packet: fetch< 2139785 refs/cache-automerge/36/d80bf5d1b574c01c54abe8fdf0d225ed5a8f71 .... // then the refs/changes/*
That is a major burden when on a slow network connection and probably add stress on our Gerrit server.
From the C git manual, we can hide references from the initial advertisement of references:
uploadpack.hideRefs
String(s) upload-pack uses to decide which refs to omit from its initial advertisement. Use more than one definitions to specify multiple prefix strings.
A ref that are under the hierarchies listed on the value of this variable is excluded, and is hidden from git ls-remote, git fetch, etc. An attempt to fetch a hidden ref by git fetch will fail. See also uploadpack.allowtipsha1inwant.
uploadpack.allowtipsha1inwant
When uploadpack.hideRefs is in effect, allow upload-pack to accept a fetch request that asks for an object at the tip of a hidden ref (by default, such a request is rejected). see also uploadpack.hideRefs.
In theory we might want to set on all repositories:
uploadpack.hiderefs=refs/changes uploadpack.hiderefs=refs/cache-automerge uploadpack.allowtipsha1inwant=true
That was apparently introduced in jgit with e747517 which is apparently included since jgit v3.1.0.201309270735-rc1.
So that should be included in the version we have bundled:
$ unzip -l /var/lib/gerrit2/review_site/bin/gerrit.war|grep -i jgit 4540 2014-07-01 18:25 WEB-INF/lib/gerrit-patch-jgit-server.jar 81372 2014-07-01 18:25 WEB-INF/lib/org.eclipse.jgit.http.server-3.1.0.201310021548-r.jar 1771070 2014-07-01 18:25 WEB-INF/lib/org.eclipse.jgit-3.1.0.201310021548-r.jar
I found a bug filled for Gerrit at https://code.google.com/p/gerrit/issues/detail?id=175