diff options
Diffstat (limited to 'apps/dav/tests/benchmarks')
-rwxr-xr-x | apps/dav/tests/benchmarks/benchmark.sh | 55 | ||||
-rwxr-xr-x | apps/dav/tests/benchmarks/bulk_upload.sh | 81 | ||||
-rwxr-xr-x | apps/dav/tests/benchmarks/single_upload.sh | 64 |
3 files changed, 200 insertions, 0 deletions
diff --git a/apps/dav/tests/benchmarks/benchmark.sh b/apps/dav/tests/benchmarks/benchmark.sh new file mode 100755 index 00000000000..613a83fe68a --- /dev/null +++ b/apps/dav/tests/benchmarks/benchmark.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# +# SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later +# +set -eu + +# benchmark.sh + +export KB=1000 +export MB=$((KB*1000)) + +MAX_UPLOAD_SIZE=$((512*KB)) + +export CONCURRENCY=5 +export BANDWIDTH=$((100*MB/CONCURRENCY)) + +FILE_SIZES=($((1*KB)) $((10*KB)) $((100*KB))) + +echo "Concurrency: $CONCURRENCY" +echo "Bandwidth: $BANDWIDTH" + +md_output="# Bulk upload benchmark\n" +md_output+="\n" +md_output+="- Concurrency: $CONCURRENCY\n" +md_output+="- Bandwidth: ${BANDWIDTH}B\n" +md_output+="\n" +md_output+="| Nb | Size (B) | Bundle (sec) | Single (sec) |\n" +md_output+="|---|---|---|---|\n" + +requests_count='1 2 3 4 5' + +for size in "${FILE_SIZES[@]}" +do + nb=$((MAX_UPLOAD_SIZE/size)) + + echo "- Upload of $nb tiny file of ${size}B" + echo " - Bundled" + start=$(date +%s) + echo "$requests_count" | xargs -d ' ' -P $CONCURRENCY -I{} ./bulk_upload.sh "$nb" "$size" + end=$(date +%s) + bulk_exec_time=$((end-start)) + echo "${bulk_exec_time}s" + + echo " - Single" + start=$(date +%s) + echo "$requests_count" | xargs -d ' ' -P $CONCURRENCY -I{} ./single_upload.sh "$nb" "$size" + end=$(date +%s) + single_exec_time=$((end-start)) + echo "${single_exec_time}s" + + md_output+="| $nb | $size | $bulk_exec_time | $single_exec_time |\n" +done + +echo -en "$md_output"
\ No newline at end of file diff --git a/apps/dav/tests/benchmarks/bulk_upload.sh b/apps/dav/tests/benchmarks/bulk_upload.sh new file mode 100755 index 00000000000..346403a3d61 --- /dev/null +++ b/apps/dav/tests/benchmarks/bulk_upload.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# +# SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later +# +set -eu + +# bulk_upload.sh <nb-of-files> <size-of-files> + +KB=${KB:-100} +MB=${MB:-$((KB*1000))} + +NB=$1 +SIZE=$2 + +CONCURRENCY=${CONCURRENCY:-1} +BANDWIDTH=${BANDWIDTH:-$((100*MB/CONCURRENCY))} + +USER="admin" +PASS="password" +SERVER="nextcloud.test" +UPLOAD_PATH="/tmp/bulk_upload_request_$(openssl rand --hex 8).txt" +BOUNDARY="boundary_$(openssl rand --hex 8)" +LOCAL_FOLDER="/tmp/bulk_upload/${BOUNDARY}_${NB}_${SIZE}" +REMOTE_FOLDER="/bulk_upload/${BOUNDARY}_${NB}_${SIZE}" + +mkdir --parent "$LOCAL_FOLDER" + +for ((i=1; i<="$NB"; i++)) +do + 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" + file_mtime=$(stat -c %Y "$file_local_path") + file_hash=$(md5sum "$file_local_path" | awk '{ print $1 }') + file_size=$(du -sb "$file_local_path" | awk '{ print $1 }') + + { + echo -en "--$BOUNDARY\r\n" + # echo -en "Content-ID: $file_name\r\n" + echo -en "X-File-Path: $file_remote_path\r\n" + echo -en "X-OC-Mtime: $file_mtime\r\n" + # echo -en "X-File-Id: $file_id\r\n" + echo -en "X-File-Md5: $file_hash\r\n" + echo -en "Content-Length: $file_size\r\n" + echo -en "\r\n" >> "$UPLOAD_PATH" + + cat "$file_local_path" + echo -en "\r\n" >> "$UPLOAD_PATH" + } >> "$UPLOAD_PATH" +done + +echo -en "--$BOUNDARY--\r\n" >> "$UPLOAD_PATH" + +echo "Creating folder /bulk_upload" +curl \ + -X MKCOL \ + -k \ + "https://$USER:$PASS@$SERVER/remote.php/dav/files/$USER/bulk_upload" > /dev/null + +echo "Creating folder $REMOTE_FOLDER" +curl \ + -X MKCOL \ + -k \ + "https://$USER:$PASS@$SERVER/remote.php/dav/files/$USER/$REMOTE_FOLDER" + +echo "Uploading $NB files with total size: $(du -sh "$UPLOAD_PATH" | cut -d ' ' -f1)" +echo "Local file is: $UPLOAD_PATH" +curl \ + -X POST \ + -k \ + --progress-bar \ + --limit-rate "${BANDWIDTH}k" \ + --cookie "XDEBUG_PROFILE=true;path=/;" \ + -H "Content-Type: multipart/related; boundary=$BOUNDARY" \ + --data-binary "@$UPLOAD_PATH" \ + "https://$USER:$PASS@$SERVER/remote.php/dav/bulk" + +rm -rf "${LOCAL_FOLDER:?}" +rm "$UPLOAD_PATH" diff --git a/apps/dav/tests/benchmarks/single_upload.sh b/apps/dav/tests/benchmarks/single_upload.sh new file mode 100755 index 00000000000..e28a5deedb9 --- /dev/null +++ b/apps/dav/tests/benchmarks/single_upload.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later +# +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:?}"/*
\ No newline at end of file |