#!/bin/bash # # gRPC Load Test using ghz (Go-based gRPC benchmarking tool) # # Install ghz: https://github.com/bojand/ghz # MacOS: brew install ghz # Linux: Download from releases set -e echo "=======================================================================" echo " FOXHUNT TRADING SERVICE - gRPC LOAD TEST (ghz)" echo "=======================================================================" echo "" # Check if ghz is installed if ! command -v ghz &> /dev/null; then echo "❌ ghz is not installed" echo "" echo "Install with:" echo " Ubuntu/Debian: wget https://github.com/bojand/ghz/releases/download/v0.117.0/ghz-linux-x86_64.tar.gz && tar -xzf ghz-linux-x86_64.tar.gz && sudo mv ghz /usr/local/bin/" echo " MacOS: brew install ghz" echo " Arch: yay -S ghz" echo "" exit 1 fi # Check if grpcurl is available (for service inspection) if command -v grpcurl &> /dev/null; then echo "✅ grpcurl available for service inspection" else echo "⚠️ grpcurl not available (optional)" fi # Configuration GRPC_HOST="localhost:50052" PROTO_PATH="tli/proto/trading.proto" SERVICE="foxhunt.tli.TradingService" METHOD="SubmitOrder" echo "Configuration:" echo " gRPC Host: $GRPC_HOST" echo " Proto: $PROTO_PATH" echo " Service: $SERVICE" echo " Method: $METHOD" echo "" # Test 1: Baseline (low load) echo "=======================================================================" echo " TEST 1: BASELINE (1,000 requests, 10 RPS)" echo "=======================================================================" ghz --proto "$PROTO_PATH" \ --import-paths="." \ --call "$SERVICE/$METHOD" \ --insecure \ --total 1000 \ --concurrency 10 \ --rps 10 \ --data '{ "symbol": "BTC/USD", "side": "BUY", "order_type": "LIMIT", "quantity": 1.0, "price": 50000.0, "time_in_force": "GTC", "client_order_id": "test-{{.RequestNumber}}" }' \ "$GRPC_HOST" || echo "⚠️ Test 1 failed or partially completed" echo "" # Test 2: Medium load echo "=======================================================================" echo " TEST 2: MEDIUM LOAD (5,000 requests, 500 RPS, 50 concurrent)" echo "=======================================================================" ghz --proto "$PROTO_PATH" \ --import-paths="." \ --call "$SERVICE/$METHOD" \ --insecure \ --total 5000 \ --concurrency 50 \ --rps 500 \ --data '{ "symbol": "ETH/USD", "side": "SELL", "order_type": "LIMIT", "quantity": 10.0, "price": 3000.0, "time_in_force": "GTC", "client_order_id": "test-{{.RequestNumber}}" }' \ "$GRPC_HOST" || echo "⚠️ Test 2 failed or partially completed" echo "" # Test 3: High load (target: 10K orders/sec) echo "=======================================================================" echo " TEST 3: HIGH LOAD (10,000 requests, 10K RPS, 100 concurrent)" echo "=======================================================================" ghz --proto "$PROTO_PATH" \ --import-paths="." \ --call "$SERVICE/$METHOD" \ --insecure \ --total 10000 \ --concurrency 100 \ --rps 10000 \ --data '{ "symbol": "SOL/USD", "side": "BUY", "order_type": "MARKET", "quantity": 100.0, "time_in_force": "IOC", "client_order_id": "test-{{.RequestNumber}}" }' \ "$GRPC_HOST" || echo "⚠️ Test 3 failed or partially completed" echo "" # Test 4: Sustained load (5 minutes at 1K RPS) echo "=======================================================================" echo " TEST 4: SUSTAINED LOAD (5 minutes, 1K RPS)" echo "=======================================================================" echo "Running sustained load for 5 minutes (300,000 total requests)..." ghz --proto "$PROTO_PATH" \ --import-paths="." \ --call "$SERVICE/$METHOD" \ --insecure \ --duration 300s \ --concurrency 100 \ --rps 1000 \ --data '{ "symbol": "AVAX/USD", "side": "{{randomString (\"BUY\" \"SELL\")}}", "order_type": "LIMIT", "quantity": {{randomInt 1 100}}, "price": {{randomInt 10 100}}, "time_in_force": "GTC", "client_order_id": "sustained-{{.RequestNumber}}" }' \ "$GRPC_HOST" || echo "⚠️ Test 4 failed or partially completed" echo "" echo "=======================================================================" echo " LOAD TEST COMPLETE" echo "=======================================================================" echo "" echo "Check Prometheus metrics:" echo " http://localhost:9092/metrics" echo "" echo "Check Grafana dashboards:" echo " http://localhost:3000" echo ""