#!/bin/bash # Simple Concurrent Connection Test using curl for HTTP health endpoints # Tests Trading Service, API Gateway, Backtesting, and ML Training services set -e echo "Foxhunt Concurrent Connection Test" echo "====================================" echo "" # Test configuration TRADING_HEALTH="http://localhost:8081/health" API_GW_HEALTH="http://localhost:8080/health" BACKTESTING_HEALTH="http://localhost:8082/health" ML_TRAINING_HEALTH="http://localhost:8095/health" # Function to test concurrent connections test_concurrent() { local url=$1 local num_connections=$2 local service_name=$3 echo "" echo "Testing $service_name with $num_connections concurrent connections..." local start_time=$(date +%s%N) local success=0 local failed=0 local total_latency=0 # Create temporary file for results local results_file=$(mktemp) # Launch concurrent requests for i in $(seq 1 $num_connections); do ( local req_start=$(date +%s%N) if curl -s -f -m 5 "$url" > /dev/null 2>&1; then local req_end=$(date +%s%N) local latency=$(( (req_end - req_start) / 1000000 )) echo "SUCCESS:$latency" >> "$results_file" else echo "FAILED:0" >> "$results_file" fi ) & done # Wait for all requests to complete wait local end_time=$(date +%s%N) local total_duration=$(( (end_time - start_time) / 1000000 )) # Analyze results while IFS=: read -r status latency; do if [ "$status" = "SUCCESS" ]; then ((success++)) total_latency=$((total_latency + latency)) else ((failed++)) fi done < "$results_file" local total=$((success + failed)) local success_rate=0 local avg_latency=0 local throughput=0 if [ $total -gt 0 ]; then success_rate=$(awk "BEGIN {printf \"%.1f\", ($success / $total) * 100}") fi if [ $success -gt 0 ]; then avg_latency=$((total_latency / success)) fi if [ $total_duration -gt 0 ]; then throughput=$(awk "BEGIN {printf \"%.2f\", ($success * 1000.0) / $total_duration}") fi echo " Success: $success/$total ($success_rate%)" echo " Failed: $failed" echo " Avg Latency: ${avg_latency}ms" echo " Duration: ${total_duration}ms" echo " Throughput: ${throughput} req/s" rm -f "$results_file" # Return success rate (for final assessment) echo "$success_rate" } echo "Starting concurrent connection tests..." echo "" # Test each service with increasing connection counts for connections in 10 50 100 200; do echo "" echo "========================================" echo "Testing with $connections connections" echo "========================================" test_concurrent "$TRADING_HEALTH" $connections "Trading Service" test_concurrent "$API_GW_HEALTH" $connections "API Gateway" test_concurrent "$BACKTESTING_HEALTH" $connections "Backtesting Service" test_concurrent "$ML_TRAINING_HEALTH" $connections "ML Training Service" if [ $connections -lt 200 ]; then echo "" echo "Waiting 5 seconds before next test level..." sleep 5 fi done echo "" echo "========================================" echo "Connection Leak Check" echo "========================================" echo "" echo "Active connections on service ports:" netstat -an | grep -E ":(50051|50052|50053|50054|8080|8081|8082|8095)" | grep ESTABLISHED | wc -l echo "" echo "Connection summary:" ss -s | grep TCP echo "" echo "Test completed successfully!"