Skip to content

Commit

Permalink
Add benchmark tests
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Oct 11, 2021
1 parent 1490b2a commit caeb257
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 231 deletions.
50 changes: 50 additions & 0 deletions apps/dav/tests/temporary/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

set -eu

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{} ./bundle_upload.sh "$nb" "$size"
end=$(date +%s)
bundle_exec_time=$((end-start))
echo "${bundle_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 | $bundle_exec_time | $single_exec_time |\n"
done

echo -en "$md_output"
70 changes: 70 additions & 0 deletions apps/dav/tests/temporary/bundle_upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -eu

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/bundle_upload_request_$(openssl rand --hex 8).txt"
BOUNDARY="boundary_$(openssl rand --hex 8)"
LOCAL_FOLDER="/tmp/bundle_upload/${BOUNDARY}_${NB}_${SIZE}"
REMOTE_FOLDER="/bundle_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-File-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 /${BOUNDARY}_${NB}_${SIZE}"
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"
blackfire curl \
-X POST \
-k \
--progress-bar \
--limit-rate "${BANDWIDTH}k" \
--cookie "XDEBUG_PROFILE=MROW4A;path=/;" \
-H "Content-Type: multipart/related; boundary=$BOUNDARY" \
--data-binary "@$UPLOAD_PATH" \
"https://$USER:$PASS@$SERVER/remote.php/dav/files/bundle"

rm -rf "${LOCAL_FOLDER:?}"
rm "$UPLOAD_PATH"
149 changes: 0 additions & 149 deletions apps/dav/tests/temporary/bundling_profile.sh

This file was deleted.

70 changes: 0 additions & 70 deletions apps/dav/tests/temporary/bundling_tests.sh

This file was deleted.

12 changes: 0 additions & 12 deletions apps/dav/tests/temporary/put_test.sh

This file was deleted.

Binary file removed apps/dav/tests/temporary/screenshot.png
Binary file not shown.
Loading

0 comments on commit caeb257

Please sign in to comment.