run-enhanced-benchmarks.sh
1 #!/bin/bash 2 3 # Script to run enhanced benchmarks for the adaptive chunking system 4 # This script will: 5 # 1. Create test files of various sizes 6 # 2. Run benchmarks for different operations and providers 7 # 3. Generate benchmark reports 8 9 set -e 10 11 echo "Enhanced Adaptive Chunking Benchmark Suite" 12 echo "==========================================" 13 14 # Create benchmark directory 15 BENCHMARK_DIR="benchmark-results/$(date +%Y%m%d-%H%M%S)" 16 mkdir -p "$BENCHMARK_DIR" 17 mkdir -p "$BENCHMARK_DIR/test-files" 18 19 # Create test files of various sizes 20 create_test_file() { 21 local size=$1 22 local file="$BENCHMARK_DIR/test-files/$2" 23 24 echo "Creating test file: $file ($size bytes)" 25 26 # Create a pattern that repeats 27 dd if=/dev/urandom bs=1024 count=1 of="$BENCHMARK_DIR/test-files/pattern.dat" 2>/dev/null 28 29 # Create the file by repeating the pattern 30 local remaining=$size 31 local block_size=1048576 # 1MB 32 33 # Create an empty file 34 > "$file" 35 36 while [ $remaining -gt 0 ]; do 37 if [ $remaining -lt $block_size ]; then 38 block_size=$remaining 39 fi 40 41 dd if="$BENCHMARK_DIR/test-files/pattern.dat" bs=1 count=$block_size >> "$file" 2>/dev/null 42 43 remaining=$((remaining - block_size)) 44 done 45 46 # Verify file size 47 local actual_size=$(stat -c%s "$file") 48 echo " File created: $actual_size bytes" 49 } 50 51 # Create test files 52 echo "Creating test files..." 53 create_test_file 1024 "text-1K.txt" 54 create_test_file 10240 "text-10K.txt" 55 create_test_file 102400 "text-100K.txt" 56 create_test_file 1048576 "text-1M.txt" 57 create_test_file 10485760 "text-10M.txt" 58 create_test_file 104857600 "text-100M.txt" 59 60 # Create binary files 61 echo "Creating binary files..." 62 create_test_file 1024 "binary-1K.bin" 63 create_test_file 10240 "binary-10K.bin" 64 create_test_file 102400 "binary-100K.bin" 65 create_test_file 1048576 "binary-1M.bin" 66 create_test_file 10485760 "binary-10M.bin" 67 create_test_file 104857600 "binary-100M.bin" 68 69 # Create modified versions of files for differential benchmarks 70 echo "Creating modified versions of files..." 71 for file in "$BENCHMARK_DIR/test-files/"*; do 72 if [[ -f "$file" && ! "$file" =~ pattern.dat ]]; then 73 modified_file="${file%.*}-v2.${file##*.}" 74 cp "$file" "$modified_file" 75 76 # Modify ~10% of the file 77 filesize=$(stat -c%s "$file") 78 modify_size=$((filesize / 10)) 79 modify_offset=$((RANDOM % (filesize - modify_size))) 80 81 dd if=/dev/urandom of="$modified_file" bs=1 count=$modify_size seek=$modify_offset conv=notrunc 2>/dev/null 82 83 echo " Created modified version: $modified_file" 84 fi 85 done 86 87 # Run benchmarks 88 echo "Running benchmarks..." 89 90 # Build the benchmark tool 91 echo "Building benchmark tool..." 92 go build -o "$BENCHMARK_DIR/benchmark-tool" ./cmd/keepsync-cli/tools/benchmark.go 93 94 # Run benchmarks for different file sizes and operations 95 echo "Running file size benchmarks..." 96 for size in "1K" "10K" "100K" "1M" "10M" "100M"; do 97 echo " Benchmarking $size files..." 98 99 # Text files 100 "$BENCHMARK_DIR/benchmark-tool" \ 101 --file "$BENCHMARK_DIR/test-files/text-$size.txt" \ 102 --output "$BENCHMARK_DIR/text-$size-benchmark.json" \ 103 --operations "upload,download,list,delete" \ 104 --providers "local,s3,webdav,sftp" \ 105 --iterations 5 \ 106 --warmup 2 107 108 # Binary files 109 "$BENCHMARK_DIR/benchmark-tool" \ 110 --file "$BENCHMARK_DIR/test-files/binary-$size.bin" \ 111 --output "$BENCHMARK_DIR/binary-$size-benchmark.json" \ 112 --operations "upload,download,list,delete" \ 113 --providers "local,s3,webdav,sftp" \ 114 --iterations 5 \ 115 --warmup 2 116 done 117 118 # Run differential benchmarks 119 echo "Running differential benchmarks..." 120 for size in "1M" "10M" "100M"; do 121 echo " Benchmarking differential $size files..." 122 123 # Text files 124 "$BENCHMARK_DIR/benchmark-tool" \ 125 --file "$BENCHMARK_DIR/test-files/text-$size.txt" \ 126 --modified-file "$BENCHMARK_DIR/test-files/text-$size-v2.txt" \ 127 --output "$BENCHMARK_DIR/text-$size-diff-benchmark.json" \ 128 --operations "differential" \ 129 --providers "local,s3,webdav,sftp" \ 130 --iterations 5 \ 131 --warmup 2 132 133 # Binary files 134 "$BENCHMARK_DIR/benchmark-tool" \ 135 --file "$BENCHMARK_DIR/test-files/binary-$size.bin" \ 136 --modified-file "$BENCHMARK_DIR/test-files/binary-$size-v2.bin" \ 137 --output "$BENCHMARK_DIR/binary-$size-diff-benchmark.json" \ 138 --operations "differential" \ 139 --providers "local,s3,webdav,sftp" \ 140 --iterations 5 \ 141 --warmup 2 142 done 143 144 # Run network condition benchmarks 145 echo "Running network condition benchmarks..." 146 for condition in "lan" "wan" "high-latency" "low-bandwidth"; do 147 echo " Benchmarking with $condition network conditions..." 148 149 "$BENCHMARK_DIR/benchmark-tool" \ 150 --file "$BENCHMARK_DIR/test-files/text-10M.txt" \ 151 --output "$BENCHMARK_DIR/network-$condition-benchmark.json" \ 152 --operations "upload,download" \ 153 --providers "local,s3,webdav,sftp" \ 154 --network-condition "$condition" \ 155 --iterations 5 \ 156 --warmup 2 157 done 158 159 # Generate summary report 160 echo "Generating summary report..." 161 "$BENCHMARK_DIR/benchmark-tool" \ 162 --generate-report \ 163 --input "$BENCHMARK_DIR" \ 164 --output "$BENCHMARK_DIR/benchmark-report.md" 165 166 # Generate CSV summary 167 echo "Generating CSV summary..." 168 "$BENCHMARK_DIR/benchmark-tool" \ 169 --generate-csv \ 170 --input "$BENCHMARK_DIR" \ 171 --output "$BENCHMARK_DIR/summary.csv" 172 173 echo "Benchmarks completed!" 174 echo "Results available in: $BENCHMARK_DIR" 175 echo "Summary report: $BENCHMARK_DIR/benchmark-report.md" 176 echo "CSV summary: $BENCHMARK_DIR/summary.csv"