#!/bin/bash # MarkBase Archive Module Performance Test Script echo "=========================================" echo "MarkBase Archive Performance Test Suite" echo "=========================================" # Configuration SERVER_URL="http://localhost:11438" UPLOAD_ENDPOINT="/api/v2/upload" USER_ID="perf_test" TEST_DIR="/tmp/markbase_perf_test" LOG_FILE="/tmp/markbase_perf_results.log" # Create test directory mkdir -p $TEST_DIR # Function to generate test ZIP files generate_test_zip() { size=$1 name=$2 echo "Generating $size MB test ZIP file..." # Create temp directory with files temp_dir=$(mktemp -d) for i in {1..10}; do dd if=/dev/urandom of="$temp_dir/file_$i.txt" bs=1M count=$((size / 10)) 2>/dev/null done # Create ZIP cd $temp_dir zip -r "$TEST_DIR/$name" . >/dev/null 2>&1 cd - rm -rf $temp_dir echo "Generated $TEST_DIR/$name ($(du -h $TEST_DIR/$name | cut -f1))" } # Function to test upload performance test_upload() { file=$1 description=$2 echo "" echo "Testing: $description" echo "File: $file" # Measure upload time start_time=$(date +%s%N) response=$(curl -s -w "\n%{http_code}\n%{time_total}" \ -X POST "$SERVER_URL$UPLOAD_ENDPOINT/$USER_ID" \ -F "file=@$file") end_time=$(date +%s%N) # Parse response http_code=$(echo "$response" | tail -n 2 | head -n 1) time_total=$(echo "$response" | tail -n 1) json_response=$(echo "$response" | head -n -2) # Calculate duration in milliseconds duration_ms=$(( (end_time - start_time) / 1000000 )) # Log results echo "HTTP Code: $http_code" echo "Upload Time: ${time_total}s" echo "Duration: ${duration_ms}ms" if [ "$http_code" == "201" ]; then echo "✅ Upload successful" # Check if extracted field exists if echo "$json_response" | jq -e '.extracted' >/dev/null 2>&1; then extracted_count=$(echo "$json_response" | jq -r '.extracted.count') extracted_bytes=$(echo "$json_response" | jq -r '.extracted.bytes') echo "✅ Extracted: $extracted_count files, $extracted_bytes bytes" echo "SUCCESS|$description|$http_code|${time_total}s|${duration_ms}ms|$extracted_count|$extracted_bytes" >> $LOG_FILE else echo "⚠️ No extracted field in response" echo "PARTIAL|$description|$http_code|${time_total}s|${duration_ms}ms" >> $LOG_FILE fi else echo "❌ Upload failed" echo "FAILED|$description|$http_code|${time_total}s|${duration_ms}ms" >> $LOG_FILE fi } # Function to test concurrent uploads test_concurrent() { count=$1 echo "" echo "Testing concurrent uploads: $count simultaneous" # Generate small test files for i in {1..$count}; do temp_dir=$(mktemp -d) echo "file $i content" > "$temp_dir/test_$i.txt" cd $temp_dir zip -r "$TEST_DIR/concurrent_$i.zip" test_$i.txt >/dev/null 2>&1 cd - rm -rf $temp_dir done # Run concurrent uploads start_time=$(date +%s%N) for i in {1..$count}; do curl -s -X POST "$SERVER_URL$UPLOAD_ENDPOINT/concurrent_test" \ -F "file=@$TEST_DIR/concurrent_$i.zip" & done # Wait for all to complete wait end_time=$(date +%s%N) duration_ms=$(( (end_time - start_time) / 1000000 )) echo "Total time for $count concurrent uploads: ${duration_ms}ms" echo "CONCURRENT|$count uploads|${duration_ms}ms" >> $LOG_FILE # Cleanup rm -f $TEST_DIR/concurrent_*.zip } # Main test execution echo "" echo "Starting performance tests..." echo "Log file: $LOG_FILE" echo "" # Test 1: Small file (10MB) generate_test_zip 10 "test_10mb.zip" test_upload "$TEST_DIR/test_10mb.zip" "10MB ZIP file" # Test 2: Medium file (100MB) generate_test_zip 100 "test_100mb.zip" test_upload "$TEST_DIR/test_100mb.zip" "100MB ZIP file" # Test 3: Large file (1GB) - Optional, comment out if needed # generate_test_zip 1000 "test_1gb.zip" # test_upload "$TEST_DIR/test_1gb.zip" "1GB ZIP file" # Test 4: Concurrent uploads (10) test_concurrent 10 # Test 5: Concurrent uploads (50) test_concurrent 50 echo "" echo "=========================================" echo "Performance tests completed" echo "Results saved to: $LOG_FILE" echo "=========================================" echo "" echo "Summary:" cat $LOG_FILE # Cleanup rm -rf $TEST_DIR