I've an application that requires to run git add
/commit
/push
on each single file i'd like to push, in order to trigger a Gitlab Job on each.
My problem is that git is actually taking many time to do the git push
command.
Here are the commands i'm using:
git add myFile.json
git commit myFile.json -m "commitMessage"
variable1 = git rev-parse HEAD # Storing last commit hash into a variable
# Pushing only one specific commit to (maybe) make it faster
git push $variable1:master
What i'd like to do is to make the whole process "faster". What i've thought about:
- Doing multiple pipeline triggers using only one
git push
(maybe by running the pipeline on each commit instead of each push), but it doesn't seem possible. - Doing multiple pushes in one
git push
command, so it doesn't have to reload some of thegit push
init operations before each file pushed (i have no idea on what is happenning during thegit push
process, so that idea may be wrong)
Does anyone has an idea on how to make this process faster, by using one of my ideas, or even a brand new one from you !
Note: I'm using HTTPS, so SSH solutions probably won't fit here.
Output of push command:
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 2 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 521 bytes | 521.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0)
To https://gitlab/root/xxx.git
bd0a7c1..9671b26 master -> master
Thanks in advance !
Edit 1:
Here is the output of GIT_TRACE=true GIT_TRACE_PACKET=true git push
12:47:38.387505 git.c:418 trace: built-in: git push https://root:password@gitlab/root/xxx.git
12:47:38.405394 run-command.c:643 trace: run_command: GIT_DIR=.git git-remote-https https://root:password@gitlab/root/xxx.git https://root:password@gitlab/root/xxx.git
12:47:39.926614 pkt-line.c:80 packet: git< # service=git-receive-pack
12:47:39.926654 pkt-line.c:80 packet: git< 0000
12:47:39.926664 pkt-line.c:80 packet: git< 4a902e3cdd3c06ba7fe9aa0345e510ce7c7ebb73 refs/heads/master\0report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta push-options object-format=sha1 agent=git/2.33.1.gl3
12:47:39.926678 pkt-line.c:80 packet: git< 0000
12:47:39.931365 pkt-line.c:80 packet: git> refs/heads/master:refs/heads/master
12:47:39.934089 pkt-line.c:80 packet: git> 0000
12:47:39.934131 run-command.c:643 trace: run_command: git send-pack --stateless-rpc --helper-status --thin --progress https://root:password@gitlab/root/xxx.git/ --stdin
12:47:39.954005 git.c:418 trace: built-in: git send-pack --stateless-rpc --helper-status --thin --progress https://root:password@gitlab/root/xxx.git/ --stdin
12:47:39.962814 pkt-line.c:80 packet: git< refs/heads/master:refs/heads/master
12:47:39.962841 pkt-line.c:80 packet: git< 0000
12:47:39.965723 pkt-line.c:80 packet: git< 4a902e3cdd3c06ba7fe9aa0345e510ce7c7ebb73 refs/heads/master\0report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta push-options object-format=sha1 agent=git/2.33.1.gl3
12:47:39.965792 pkt-line.c:80 packet: git< 0000
12:47:39.998180 pkt-line.c:80 packet: git> shallow 67769ed9405583783a372dc7731d5c1be8801a63
12:47:39.998324 pkt-line.c:80 packet: git> 4a902e3cdd3c06ba7fe9aa0345e510ce7c7ebb73 4f72bdb2e340f297c5c88a3433bf1700a010f721 refs/heads/master\0 report-status side-band-64k agent=git/2.20.1
12:47:39.998420 pkt-line.c:80 packet: git> 0000
12:47:39.998841 pkt-line.c:80 packet: git< 0035shallow 67769ed9405583783a372dc7731d5c1be8801a6300954a902e3cdd3c06ba7fe9aa0345e510ce7c7ebb73 4f72bdb2e340f297c5c88a3433bf1700a010f721 refs/heads/master\0 report-status side-band-64k agent=git/2.20.10000
12:47:39.998986 run-command.c:643 trace: run_command: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress --shallow
12:47:40.007547 git.c:418 trace: built-in: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress --shallow
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 2 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 530 bytes | 530.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0)
12:47:40.202197 pkt-line.c:80 packet: git> 0000
12:47:40.202196 pkt-line.c:80 packet: git< PACK ...
12:47:41.680994 pkt-line.c:80 packet: sideband< \1000eunpack ok0019ok refs/heads/master0000
12:47:41.681027 pkt-line.c:80 packet: sideband< 0000
12:47:41.681108 pkt-line.c:80 packet: git< unpack ok
12:47:41.681132 pkt-line.c:80 packet: git< ok refs/heads/master
12:47:41.681148 pkt-line.c:80 packet: git< 0000
12:47:41.681153 pkt-line.c:80 packet: git> 0000
To https://gitlab/root/xxx.git
4a902e3..4f72bdb master -> master
The long parts seems to be run_command: GIT_DIR=.git git-remote-https
and git<PACK ...
.
This command was used in a depth=2 git clone
.
Note: The first push
is always fast (seems to be between 1 or 2 seconds), and the subsequents ones are mostly between 3 and 4 seconds. I tried to put a sleep
between my pushes, but the duration isn't changing, so i guess it's not an issue from my code.
Here is the output of my first push:
12:46:16.834461 git.c:418 trace: built-in: git push https://root:password@gitlab/root/xxx.git
12:46:16.836817 run-command.c:643 trace: run_command: GIT_DIR=.git git-remote-https https://root:password@gitlab/root/xxx.git https://root:password@gitlab/root/xxx.git
12:46:17.307690 pkt-line.c:80 packet: git< # service=git-receive-pack
12:46:17.307951 pkt-line.c:80 packet: git< 0000
12:46:17.308003 pkt-line.c:80 packet: git< 6725c964319de48c963746e976a97634f0ee0e7c refs/heads/master\0report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta push-options object-format=sha1 agent=git/2.33.1.gl3
12:46:17.308024 pkt-line.c:80 packet: git< 0000
12:46:17.309205 pkt-line.c:80 packet: git> refs/heads/master:refs/heads/master
12:46:17.309223 pkt-line.c:80 packet: git> 0000
12:46:17.309271 run-command.c:643 trace: run_command: git send-pack --stateless-rpc --helper-status --thin --progress https://root:password@gitlab/root/xxx.git/ --stdin
12:46:17.312085 git.c:418 trace: built-in: git send-pack --stateless-rpc --helper-status --thin --progress https://root:password@gitlab/root/xxx.git/ --stdin
12:46:17.313673 pkt-line.c:80 packet: git< refs/heads/master:refs/heads/master
12:46:17.313707 pkt-line.c:80 packet: git< 0000
12:46:17.313722 pkt-line.c:80 packet: git< 6725c964319de48c963746e976a97634f0ee0e7c refs/heads/master\0report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta push-options object-format=sha1 agent=git/2.33.1.gl3
12:46:17.314002 pkt-line.c:80 packet: git< 0000
12:46:17.316186 pkt-line.c:80 packet: git> shallow 67769ed9405583783a372dc7731d5c1be8801a63
12:46:17.316209 pkt-line.c:80 packet: git> 6725c964319de48c963746e976a97634f0ee0e7c 6665f070f909ed946bf8223516f69691c15e9c29 refs/heads/master\0 report-status side-band-64k agent=git/2.20.1
12:46:17.316316 pkt-line.c:80 packet: git> 0000
12:46:17.316423 pkt-line.c:80 packet: git< 0035shallow 67769ed9405583783a372dc7731d5c1be8801a6300956725c964319de48c963746e976a97634f0ee0e7c 6665f070f909ed946bf8223516f69691c15e9c29 refs/heads/master\0 report-status side-band-64k agent=git/2.20.10000
12:46:17.316509 run-command.c:643 trace: run_command: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress --shallow
12:46:17.318598 git.c:418 trace: built-in: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress --shallow
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 2 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 521 bytes | 173.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0)
12:46:17.339570 pkt-line.c:80 packet: git< PACK ...
12:46:17.339830 pkt-line.c:80 packet: git> 0000
[03/May/2022 12:46:17] "POST /api/getStatus/ HTTP/1.1" 200 854
12:46:18.029134 pkt-line.c:80 packet: sideband< \1000eunpack ok0019ok refs/heads/master0000
12:46:18.029164 pkt-line.c:80 packet: sideband< 0000
12:46:18.029277 pkt-line.c:80 packet: git< unpack ok
12:46:18.029285 pkt-line.c:80 packet: git< ok refs/heads/master
12:46:18.029293 pkt-line.c:80 packet: git< 0000
12:46:18.029297 pkt-line.c:80 packet: git> 0000
To https://gitlab/root/xxx.git
6725c96..6665f07 master -> master
The duration of the GIT_DIR
part seems to be faster, and the git< PACK ...
is almost instant.
Edit 2:
It appeared that it was simply a performance issue from my server, but i think that @torek answer can help people searching about this subject, so i'm marking it as accepted.