git_update/performance_tests.sh

376 lines
10 KiB
Bash
Raw Normal View History

#!/bin/bash
. driglibash-base #test
2024-07-03 12:51:49 +00:00
. creation_repo.sh &> /dev/null
2024-07-02 16:00:35 +00:00
FILES_TO_KEEP='sample0'
2024-07-03 12:51:49 +00:00
REMOTE="./remote/performance_testing"
Help()
{
echo "
NAME
performance_tests.sh
SYNOPSIS
performance_tests.sh [-a] [-h] [-n number]
OPTIONS
-a excutes all the tests.
-n number executes test number
-h prints the help.
DESCRIPTION
This script is in writing. It allows you to measure memory and bandwidth usage. The first four test different cloning methods. Te following apply changes to the local remote before testing fetching and merging commands.
TEST0: classic cloning
TEST1: --single-branch cloning
TEST2: --depth=1 --no-single-branch cloning
TEST3: --depth=1 cloning
TEST4: sparse-checking 1M sample0 only cloning
_________________
TEST5: classic fetching and merging after addition of a 1M file
TEST6: classic fetching and merging, after removal of a 1M file
TEST7: classic fetching and merging, after addition then removal of a 1M file
TEST8: --depth=1 fetching and merging, after addition of a 1M file
TEST9: --depth=1 fetching and merging, after removal of a 1M file
TEST10: --depth=1 fetching and merging, after addition then removal of 1M a file"
}
#USEFUL FUNCTIONS FOR THE TESTS
get_storage_used(){
mem=$(du $1 | tail -n1 | tr -cd [:digit:])
}
2024-07-04 13:53:47 +00:00
get_bandwidth(){
2024-07-04 14:42:39 +00:00
bw="unknown"
if [ "$1" = "cloning_text" ]; then
2024-07-04 13:53:47 +00:00
bw=$(grep -e "Receiving objects:" $1 | grep -o "Receiving objects: [[:alnum:]%/(),. ]*" | tail -n1)
bw=${bw#*,}
2024-07-04 14:42:39 +00:00
elif [ "$1" = "fetching_text" ]; then
bw=$(grep -e "\->" fetching_text| grep -o "[[:digit:].]* -> [[:digit:].]* [[:alpha:]]*")
2024-07-04 13:53:47 +00:00
fi
}
2024-07-04 13:53:47 +00:00
#TESTS ON THE INITIAL POPULATING OF THE REPO
test0(){
section TEST0
echo "TEST 0 : case of classic cloning."
2024-07-03 12:51:49 +00:00
git clone --progress --no-local $1 2> cloning_text
get_storage_used "./$REPO_NAME"
2024-07-04 13:53:47 +00:00
get_bandwidth cloning_text
echo "memory usage in a classic cloning : $mem"
2024-07-04 13:53:47 +00:00
echo "bandwidth usage : $bw"
2024-07-03 12:51:49 +00:00
run rm cloning_text
#run rm -rf $REPO_NAME
}
test1(){
section TEST1
echo "TEST 1 : case of --single-branch cloning."
2024-07-03 12:51:49 +00:00
git clone --progress --single-branch --no-local $1 2> cloning_text
get_storage_used ./$REPO_NAME
2024-07-04 13:53:47 +00:00
get_bandwidth cloning_text
echo "memory usage in a --single-branch cloning : $mem"
2024-07-04 13:53:47 +00:00
echo "bandwidth usage : $bw"
2024-07-03 12:51:49 +00:00
run rm cloning_text
run rm -rf $REPO_NAME
2024-06-28 16:29:11 +00:00
}
test2(){
section TEST2
echo "TEST 2 : case of --depth=1 --no-single-branch"
2024-07-03 12:51:49 +00:00
git clone --progress --depth=1 --no-local --no-single-branch $1 2> cloning_text
get_storage_used ./$REPO_NAME
2024-07-04 13:53:47 +00:00
get_bandwidth cloning_text
echo "memory usage in a --depth=1 --no-single-branch cloning : $mem"
2024-07-04 13:53:47 +00:00
echo "bandwidth usage : $bw"
2024-07-03 12:51:49 +00:00
run rm cloning_text
run rm -rf $REPO_NAME
2024-06-28 16:29:11 +00:00
}
test3(){
section TEST3
echo "TEST 3 : case of --depth=1 with single-branch (default))"
2024-07-03 12:51:49 +00:00
git clone --progress --single-branch --no-local --depth=1 $1 2> cloning_text
get_storage_used ./$REPO_NAME
2024-07-04 13:53:47 +00:00
get_bandwidth cloning_text
echo "memory usage in a --depth=1 with single-branch cloning : $mem"
2024-07-04 13:53:47 +00:00
echo "bandwidth usage : $bw"
2024-07-03 12:51:49 +00:00
run rm cloning_text
run rm -rf $REPO_NAME
}
2024-07-01 15:57:28 +00:00
test4(){
section TEST4
2024-07-02 16:00:35 +00:00
run mkdir $REPO_NAME
2024-07-03 16:14:18 +00:00
run echo "TEST 4 : case of sparse-checking only $FILES_TO_KEEP with depth=1"
2024-07-04 13:53:47 +00:00
#creating a git repo with sparse-checking settings
2024-07-02 16:00:35 +00:00
run cd $REPO_NAME
2024-07-01 15:57:28 +00:00
run git init -q
run git config core.sparsecheckout true
2024-07-02 16:00:35 +00:00
run echo $FILES_TO_KEEP >> .git/info/sparse-checkout
2024-07-04 13:53:47 +00:00
#pulling from the remote with sparse-checking enabled
run git remote add -f origin ../$1 &> /dev/null
run git pull origin main &> /dev/null
get_storage_used .
echo "memory usage: $mem"
2024-07-05 07:41:50 +00:00
echo "bandwidth usage : unknown"
cd ..
2024-07-02 16:00:35 +00:00
run rm -rf $REPO_NAME
}
2024-07-02 16:00:35 +00:00
#TESTS ON THE UPDATING OF THE REPOSITORY
test5(){
section TEST5
run echo 'TEST 5 : case of classic fetching and merging, after addition of a 1M file'
2024-07-04 16:29:55 +00:00
#initialization
2024-07-02 16:00:35 +00:00
run git clone $1 &> /dev/null
cd $REPO_NAME
2024-07-03 14:55:26 +00:00
run git fetch --progress origin &> /dev/null
run git merge --progress origin &> /dev/null
2024-07-04 14:42:39 +00:00
get_storage_used .
mem_before=$mem
2024-07-03 12:51:49 +00:00
#modification of the remote repo
2024-07-03 14:55:26 +00:00
cd ../$REMOTE
create_random_file 'sample5' '1M' #adding a 1M file
2024-07-03 14:55:26 +00:00
run git add sample5
run git commit --quiet -m"fourth 1M sample created"
cd ../../$REPO_NAME
2024-07-04 16:29:55 +00:00
#fetching
2024-07-04 14:42:39 +00:00
run git fetch --progress origin &> /dev/null
run git checkout origin/main
run git reset --hard
#run git merge --progress &> fetching_text
get_storage_used .
mem_after=$mem
mem=$(($mem_after-$mem_before))
#get_bandwidth fetching_text
echo "memory usage: +$mem"
#echo "bandwidth usage: $bw"
2024-07-03 14:55:26 +00:00
cd ../$REMOTE
2024-07-05 07:41:50 +00:00
git reset --hard -q HEAD~1
2024-07-03 14:55:26 +00:00
cd ../..
#rm -rf performance_testing
2024-07-01 15:57:28 +00:00
}
2024-07-02 16:00:35 +00:00
test6(){
2024-07-04 16:29:55 +00:00
section TEST6
run echo 'TEST 6 : case of classic fetching and merging, after removal of a 1M file'
2024-07-04 16:29:55 +00:00
#initialization
2024-07-05 07:41:50 +00:00
run git clone $1 #&> /dev/null
cd $REPO_NAME
get_storage_used .
mem_before=$mem
#modification of the remote repo
cd ../$REMOTE
run rm sample0
run git add sample0
run git commit --quiet -m"1M sample0 deleted"
cd ../../$REPO_NAME
2024-07-04 16:29:55 +00:00
#fetching
2024-07-04 14:42:39 +00:00
run git fetch --progress origin &> /dev/null
run git checkout origin/main
run git reset --hard
#run git merge --progress &> fetching_text
get_storage_used .
mem_after=$mem
mem=$(($mem_after-$mem_before))
#get_bandwidth fetching_text
echo "memory usage: $mem"
#echo "bandwidth usage: $bw"
cd ../$REMOTE
2024-07-05 07:41:50 +00:00
git reset --hard -q HEAD~1
cd ../..
#rm -rf performance_testing
}
2024-07-03 16:14:18 +00:00
test7(){
2024-07-04 13:53:47 +00:00
section TEST7
2024-07-03 16:14:18 +00:00
run echo 'TEST 7 : case of classic fetching and merging, after addition then removal of a 1M file'
2024-07-04 16:29:55 +00:00
#initialization
2024-07-03 16:14:18 +00:00
run git clone $1 &> /dev/null
cd $REPO_NAME
get_storage_used .
mem_before=$mem
2024-07-03 16:14:18 +00:00
#modification of the remote repo
cd ../$REMOTE
create_random_file 'sample5' '1M' #adding a 1M file
2024-07-03 16:14:18 +00:00
run git add sample5
run git commit --quiet -m"fourth 1M sample created"
run rm sample5
run git add sample5
run git commit --quiet -m"1M "sample5" deleted"
cd ../../$REPO_NAME
2024-07-04 16:29:55 +00:00
#fetching
2024-07-04 14:42:39 +00:00
run git fetch --progress origin &> /dev/null
run git checkout origin/main
run git reset --hard
#run git merge --progress &> fetching_text
get_storage_used .
mem_after=$mem
mem=$(($mem_after-$mem_before))
echo "memory usage: $mem"
#echo "bandwidth usage : unknown"
2024-07-03 16:14:18 +00:00
cd ../$REMOTE
2024-07-05 07:41:50 +00:00
git reset --hard -q HEAD~2
2024-07-03 16:14:18 +00:00
cd ../..
#rm -rf performance_testing
2024-07-03 16:14:18 +00:00
}
2024-07-04 14:42:39 +00:00
test8(){
section TEST8
2024-07-04 16:29:55 +00:00
run echo 'TEST 8 : case of fetching --depth=1 and merging, after addition of a 1M file'
#initialization
2024-07-05 07:41:50 +00:00
echo $(pwd)
run git clone $1 &> /dev/null
2024-07-04 14:42:39 +00:00
cd $REPO_NAME
get_storage_used .
mem_before=$mem
#modification of the remote repo
cd ../$REMOTE
create_random_file 'sample5' '1M' #adding a 1M file
run git add sample5
run git commit --quiet -m"fourth 1M sample created"
cd ../../$REPO_NAME
2024-07-05 07:41:50 +00:00
run git fetch --progress --depth=1 origin &> /dev/null
run git checkout origin/main
run git reset --hard
#run git merge --progress --allow-unrelated-histories &> fetching_text
2024-07-04 16:29:55 +00:00
get_storage_used .
mem_after=$mem
mem=$(($mem_after-$mem_before))
#get_bandwidth fetching_text
2024-07-04 16:29:55 +00:00
echo "memory usage: +$mem"
#echo "bandwidth usage: $bw"
2024-07-04 16:29:55 +00:00
cd ../$REMOTE
2024-07-05 07:41:50 +00:00
git reset --hard -q HEAD~1 #does not work cause commits change numbers
2024-07-04 16:29:55 +00:00
cd ../..
#rm -rf performance_testing
2024-07-04 16:29:55 +00:00
}
test9(){
2024-07-05 07:41:50 +00:00
section TEST9
2024-07-04 16:29:55 +00:00
run echo 'TEST 9 : case of --depth=1 fetching and merging, after removal of a 1M file'
#initialization
run git clone $1 &> /dev/null
cd $REPO_NAME
get_storage_used .
mem_before=$mem
#modification of the remote repo
cd ../$REMOTE
run rm sample0
run git add sample0
run git commit --quiet -m"1M sample0 deleted"
cd ../../$REPO_NAME
#fetching
run git fetch --progress --depth=1 --prune origin &> text1
run git checkout origin/main
run git reset --hard
#run git merge --progress --allow-unrelated-histories &> text2
2024-07-04 14:42:39 +00:00
get_storage_used .
mem_after=$mem
mem=$(($mem_after-$mem_before))
2024-07-04 16:29:55 +00:00
echo "memory usage: $mem"
#echo "bandwidth usage: unknown"
2024-07-04 14:42:39 +00:00
cd ../$REMOTE
2024-07-05 07:41:50 +00:00
git reset --hard -q HEAD~1
2024-07-04 14:42:39 +00:00
cd ../..
#rm -rf performance_testing
2024-07-04 14:42:39 +00:00
}
2024-07-03 16:14:18 +00:00
2024-07-04 16:29:55 +00:00
test10(){
section TEST10
run echo 'TEST 10 : case of --depth=1 fetching and merging, after addition then removal of a 1M file'
run git clone $1 &> /dev/null
cd $REPO_NAME
run git fetch --progress origin &> /dev/null
run git merge --progress origin &> /dev/null
get_storage_used .
2024-07-05 07:41:50 +00:00
mem_before=$mem
2024-07-04 16:29:55 +00:00
#modification of the remote repo
cd ../$REMOTE
create_random_file 'sample5' '1M' #adding a 1M file
run git add sample5
run git commit --quiet -m"fourth 1M sample created"
run rm sample5
run git add sample5
run git commit --quiet -m"1M "sample5" deleted"
cd ../../$REPO_NAME
#fetching
2024-07-05 07:41:50 +00:00
run git fetch --progress --depth=1 origin &> /dev/null
git checkout origin/main
git reset --hard
#run git merge --progress --allow-unrelated-histories &> /dev/null
2024-07-04 16:29:55 +00:00
get_storage_used .
mem_after=$mem
mem=$(($mem_after-$mem_before))
echo "memory usage: $mem"
#echo "bandwidth usage : unknown"
2024-07-04 16:29:55 +00:00
cd ../$REMOTE
2024-07-05 07:41:50 +00:00
git reset --hard -q HEAD~2
2024-07-04 16:29:55 +00:00
cd ../..
#rm -rf performance_testing
2024-07-04 16:29:55 +00:00
}
2024-07-03 16:14:18 +00:00
while getopts ":hn:a" option; do
case $option in
h) # display Help
Help
exit;;
n)
TEST_NUM=$OPTARG;;
a)
ALL_TESTS=true;;
2024-07-03 12:51:49 +00:00
\?) # Invalid option
echo "Error: Invalid option here"
exit;;
esac
done
if [ "$ALL_TESTS" = true ]; then
2024-07-03 12:51:49 +00:00
test0 $REMOTE
test1 $REMOTE
test2 $REMOTE
test3 $REMOTE
test4 $REMOTE
test5 $REMOTE
test6 $REMOTE
2024-07-03 16:14:18 +00:00
test7 $REMOTE
2024-07-04 14:42:39 +00:00
test8 $REMOTE
2024-07-04 16:29:55 +00:00
test9 $REMOTE
test10 $REMOTE
2024-06-28 16:29:11 +00:00
elif [ -n "$TEST_NUM" ]; then
case $TEST_NUM in
0)
2024-07-03 12:51:49 +00:00
test0 $REMOTE;;
1)
2024-07-03 12:51:49 +00:00
test1 $REMOTE;;
2024-06-28 16:29:11 +00:00
2)
2024-07-03 12:51:49 +00:00
test2 $REMOTE;;
2024-06-28 16:29:11 +00:00
3)
2024-07-03 12:51:49 +00:00
test3 $REMOTE;;
2024-07-01 15:57:28 +00:00
4)
2024-07-03 12:51:49 +00:00
test4 $REMOTE;;
2024-07-02 16:00:35 +00:00
5)
2024-07-03 12:51:49 +00:00
test5 $REMOTE;;
6)
test6 $REMOTE;;
2024-07-03 16:14:18 +00:00
7)
test7 $REMOTE;;
2024-07-04 14:42:39 +00:00
8)
test8 $REMOTE;;
2024-07-04 16:29:55 +00:00
9)
test9 $REMOTE;;
10)
test10 $REMOTE;;
*)
echo "Error: Invalid test number"
die;;
esac
else
Help
fi
2024-07-02 16:00:35 +00:00
#optimize in case all tests are run
2024-07-03 14:55:26 +00:00
#adapt in case of different units