aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/benchmarks/single_upload.sh
blob: ec57e66668d4e30a0a62df7c0326655d8b22e577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash

set -eu

# single_upload.sh <nb-of-files> <size-of-files>

export KB=${KB:-100}
export MB=${MB:-$((KB*1000))}

export NB=$1
export SIZE=$2

export CONCURRENCY=${CONCURRENCY:-1}
export BANDWIDTH=${BANDWIDTH:-$((100*MB/CONCURRENCY))}

export USER="admin"
export PASS="password"
export SERVER="nextcloud.test"
export UPLOAD_ID="single_$(openssl rand --hex 8)"
export LOCAL_FOLDER="/tmp/single_upload/${UPLOAD_ID}_${NB}_${SIZE}"
export REMOTE_FOLDER="/single_upload/${UPLOAD_ID}_${NB}_${SIZE}"

mkdir --parent "$LOCAL_FOLDER"

curl \
	-X MKCOL \
	-k \
	"https://$USER:$PASS@$SERVER/remote.php/dav/files/$USER/bulk_upload" > /dev/null

curl \
	-X MKCOL \
	-k \
	--cookie "XDEBUG_SESSION=true;path=/;" \
	"https://$USER:$PASS@$SERVER/remote.php/dav/files/$USER/$REMOTE_FOLDER"

upload_file() {
	file_name=$(openssl rand --hex 8)
	file_local_path="$LOCAL_FOLDER/$file_name.txt"
	file_remote_path="$REMOTE_FOLDER/$file_name.txt"
	head -c "$SIZE" /dev/urandom > "$file_local_path"

	curl \
		-X PUT \
		-k \
		--limit-rate "${BANDWIDTH}k" \
		--data-binary @"$file_local_path" "https://$USER:$PASS@$SERVER/remote.php/webdav/$file_remote_path"
}
export -f upload_file

file_list=''
for ((i=1; i<"$NB"; i++))
do
	file_list+="$i "
done
file_list+=$NB

echo "$file_list" | xargs -d ' ' -P "$((CONCURRENCY/5))" -I{} bash -c "upload_file {}"

printf "\n"

rm -rf "${LOCAL_FOLDER:?}"/*