demo-e2e.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #!/bin/bash
  2. # SeaweedFS RDMA End-to-End Demo Script
  3. # This script demonstrates the complete integration between SeaweedFS and the RDMA sidecar
  4. set -e
  5. # Configuration
  6. RDMA_ENGINE_SOCKET="/tmp/rdma-engine.sock"
  7. DEMO_SERVER_PORT=8080
  8. RUST_ENGINE_PID=""
  9. DEMO_SERVER_PID=""
  10. # Colors for output
  11. RED='\033[0;31m'
  12. GREEN='\033[0;32m'
  13. YELLOW='\033[1;33m'
  14. BLUE='\033[0;34m'
  15. PURPLE='\033[0;35m'
  16. CYAN='\033[0;36m'
  17. NC='\033[0m' # No Color
  18. print_header() {
  19. echo -e "\n${PURPLE}===============================================${NC}"
  20. echo -e "${PURPLE}$1${NC}"
  21. echo -e "${PURPLE}===============================================${NC}\n"
  22. }
  23. print_step() {
  24. echo -e "${CYAN}🔵 $1${NC}"
  25. }
  26. print_success() {
  27. echo -e "${GREEN}✅ $1${NC}"
  28. }
  29. print_warning() {
  30. echo -e "${YELLOW}⚠️ $1${NC}"
  31. }
  32. print_error() {
  33. echo -e "${RED}❌ $1${NC}"
  34. }
  35. cleanup() {
  36. print_header "CLEANUP"
  37. if [[ -n "$DEMO_SERVER_PID" ]]; then
  38. print_step "Stopping demo server (PID: $DEMO_SERVER_PID)"
  39. kill $DEMO_SERVER_PID 2>/dev/null || true
  40. wait $DEMO_SERVER_PID 2>/dev/null || true
  41. fi
  42. if [[ -n "$RUST_ENGINE_PID" ]]; then
  43. print_step "Stopping Rust RDMA engine (PID: $RUST_ENGINE_PID)"
  44. kill $RUST_ENGINE_PID 2>/dev/null || true
  45. wait $RUST_ENGINE_PID 2>/dev/null || true
  46. fi
  47. # Clean up socket
  48. rm -f "$RDMA_ENGINE_SOCKET"
  49. print_success "Cleanup complete"
  50. }
  51. # Set up cleanup on exit
  52. trap cleanup EXIT
  53. build_components() {
  54. print_header "BUILDING COMPONENTS"
  55. print_step "Building Go components..."
  56. go build -o bin/demo-server ./cmd/demo-server
  57. go build -o bin/test-rdma ./cmd/test-rdma
  58. go build -o bin/sidecar ./cmd/sidecar
  59. print_success "Go components built"
  60. print_step "Building Rust RDMA engine..."
  61. cd rdma-engine
  62. cargo build --release
  63. cd ..
  64. print_success "Rust RDMA engine built"
  65. }
  66. start_rdma_engine() {
  67. print_header "STARTING RDMA ENGINE"
  68. print_step "Starting Rust RDMA engine..."
  69. ./rdma-engine/target/release/rdma-engine-server --debug &
  70. RUST_ENGINE_PID=$!
  71. # Wait for engine to be ready
  72. print_step "Waiting for RDMA engine to be ready..."
  73. for i in {1..10}; do
  74. if [[ -S "$RDMA_ENGINE_SOCKET" ]]; then
  75. print_success "RDMA engine ready (PID: $RUST_ENGINE_PID)"
  76. return 0
  77. fi
  78. sleep 1
  79. done
  80. print_error "RDMA engine failed to start"
  81. exit 1
  82. }
  83. start_demo_server() {
  84. print_header "STARTING DEMO SERVER"
  85. print_step "Starting SeaweedFS RDMA demo server..."
  86. ./bin/demo-server --port $DEMO_SERVER_PORT --rdma-socket "$RDMA_ENGINE_SOCKET" --enable-rdma --debug &
  87. DEMO_SERVER_PID=$!
  88. # Wait for server to be ready
  89. print_step "Waiting for demo server to be ready..."
  90. for i in {1..10}; do
  91. if curl -s "http://localhost:$DEMO_SERVER_PORT/health" > /dev/null 2>&1; then
  92. print_success "Demo server ready (PID: $DEMO_SERVER_PID)"
  93. return 0
  94. fi
  95. sleep 1
  96. done
  97. print_error "Demo server failed to start"
  98. exit 1
  99. }
  100. test_health_check() {
  101. print_header "HEALTH CHECK TEST"
  102. print_step "Testing health endpoint..."
  103. response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/health")
  104. if echo "$response" | jq -e '.status == "healthy"' > /dev/null; then
  105. print_success "Health check passed"
  106. echo "$response" | jq '.'
  107. else
  108. print_error "Health check failed"
  109. echo "$response"
  110. exit 1
  111. fi
  112. }
  113. test_capabilities() {
  114. print_header "CAPABILITIES TEST"
  115. print_step "Testing capabilities endpoint..."
  116. response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/stats")
  117. if echo "$response" | jq -e '.enabled == true' > /dev/null; then
  118. print_success "RDMA capabilities retrieved"
  119. echo "$response" | jq '.'
  120. else
  121. print_warning "RDMA not enabled, but HTTP fallback available"
  122. echo "$response" | jq '.'
  123. fi
  124. }
  125. test_needle_read() {
  126. print_header "NEEDLE READ TEST"
  127. print_step "Testing RDMA needle read..."
  128. response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/read?volume=1&needle=12345&cookie=305419896&size=1024")
  129. if echo "$response" | jq -e '.success == true' > /dev/null; then
  130. is_rdma=$(echo "$response" | jq -r '.is_rdma')
  131. source=$(echo "$response" | jq -r '.source')
  132. duration=$(echo "$response" | jq -r '.duration')
  133. data_size=$(echo "$response" | jq -r '.data_size')
  134. if [[ "$is_rdma" == "true" ]]; then
  135. print_success "RDMA fast path used! Duration: $duration, Size: $data_size bytes"
  136. else
  137. print_warning "HTTP fallback used. Duration: $duration, Size: $data_size bytes"
  138. fi
  139. echo "$response" | jq '.'
  140. else
  141. print_error "Needle read failed"
  142. echo "$response"
  143. exit 1
  144. fi
  145. }
  146. test_benchmark() {
  147. print_header "PERFORMANCE BENCHMARK"
  148. print_step "Running performance benchmark..."
  149. response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/benchmark?iterations=5&size=2048")
  150. if echo "$response" | jq -e '.benchmark_results' > /dev/null; then
  151. rdma_ops=$(echo "$response" | jq -r '.benchmark_results.rdma_ops')
  152. http_ops=$(echo "$response" | jq -r '.benchmark_results.http_ops')
  153. avg_latency=$(echo "$response" | jq -r '.benchmark_results.avg_latency')
  154. throughput=$(echo "$response" | jq -r '.benchmark_results.throughput_mbps')
  155. ops_per_sec=$(echo "$response" | jq -r '.benchmark_results.ops_per_sec')
  156. print_success "Benchmark completed:"
  157. echo -e " ${BLUE}RDMA Operations:${NC} $rdma_ops"
  158. echo -e " ${BLUE}HTTP Operations:${NC} $http_ops"
  159. echo -e " ${BLUE}Average Latency:${NC} $avg_latency"
  160. echo -e " ${BLUE}Throughput:${NC} $throughput MB/s"
  161. echo -e " ${BLUE}Operations/sec:${NC} $ops_per_sec"
  162. echo -e "\n${BLUE}Full benchmark results:${NC}"
  163. echo "$response" | jq '.benchmark_results'
  164. else
  165. print_error "Benchmark failed"
  166. echo "$response"
  167. exit 1
  168. fi
  169. }
  170. test_direct_rdma() {
  171. print_header "DIRECT RDMA ENGINE TEST"
  172. print_step "Testing direct RDMA engine communication..."
  173. echo "Testing ping..."
  174. ./bin/test-rdma ping 2>/dev/null && print_success "Direct RDMA ping successful" || print_warning "Direct RDMA ping failed"
  175. echo -e "\nTesting capabilities..."
  176. ./bin/test-rdma capabilities 2>/dev/null | head -15 && print_success "Direct RDMA capabilities successful" || print_warning "Direct RDMA capabilities failed"
  177. echo -e "\nTesting direct read..."
  178. ./bin/test-rdma read --volume 1 --needle 12345 --size 1024 2>/dev/null > /dev/null && print_success "Direct RDMA read successful" || print_warning "Direct RDMA read failed"
  179. }
  180. show_demo_urls() {
  181. print_header "DEMO SERVER INFORMATION"
  182. echo -e "${GREEN}🌐 Demo server is running at: http://localhost:$DEMO_SERVER_PORT${NC}"
  183. echo -e "${GREEN}📱 Try these URLs:${NC}"
  184. echo -e " ${BLUE}Home page:${NC} http://localhost:$DEMO_SERVER_PORT/"
  185. echo -e " ${BLUE}Health check:${NC} http://localhost:$DEMO_SERVER_PORT/health"
  186. echo -e " ${BLUE}Statistics:${NC} http://localhost:$DEMO_SERVER_PORT/stats"
  187. echo -e " ${BLUE}Read needle:${NC} http://localhost:$DEMO_SERVER_PORT/read?volume=1&needle=12345&cookie=305419896&size=1024"
  188. echo -e " ${BLUE}Benchmark:${NC} http://localhost:$DEMO_SERVER_PORT/benchmark?iterations=5&size=2048"
  189. echo -e "\n${GREEN}📋 Example curl commands:${NC}"
  190. echo -e " ${CYAN}curl \"http://localhost:$DEMO_SERVER_PORT/health\" | jq '.'${NC}"
  191. echo -e " ${CYAN}curl \"http://localhost:$DEMO_SERVER_PORT/read?volume=1&needle=12345&size=1024\" | jq '.'${NC}"
  192. echo -e " ${CYAN}curl \"http://localhost:$DEMO_SERVER_PORT/benchmark?iterations=10\" | jq '.benchmark_results'${NC}"
  193. }
  194. interactive_mode() {
  195. print_header "INTERACTIVE MODE"
  196. show_demo_urls
  197. echo -e "\n${YELLOW}Press Enter to run automated tests, or Ctrl+C to exit and explore manually...${NC}"
  198. read -r
  199. }
  200. main() {
  201. print_header "🚀 SEAWEEDFS RDMA END-TO-END DEMO"
  202. echo -e "${GREEN}This demonstration shows:${NC}"
  203. echo -e " ✅ Complete Go ↔ Rust IPC integration"
  204. echo -e " ✅ SeaweedFS RDMA client with HTTP fallback"
  205. echo -e " ✅ High-performance needle reads via RDMA"
  206. echo -e " ✅ Performance benchmarking capabilities"
  207. echo -e " ✅ Production-ready error handling and logging"
  208. # Check dependencies
  209. if ! command -v jq &> /dev/null; then
  210. print_error "jq is required for this demo. Please install it: brew install jq"
  211. exit 1
  212. fi
  213. if ! command -v curl &> /dev/null; then
  214. print_error "curl is required for this demo."
  215. exit 1
  216. fi
  217. # Build and start components
  218. build_components
  219. start_rdma_engine
  220. sleep 2 # Give engine time to fully initialize
  221. start_demo_server
  222. sleep 2 # Give server time to connect to engine
  223. # Show interactive information
  224. interactive_mode
  225. # Run automated tests
  226. test_health_check
  227. test_capabilities
  228. test_needle_read
  229. test_benchmark
  230. test_direct_rdma
  231. print_header "🎉 END-TO-END DEMO COMPLETE!"
  232. echo -e "${GREEN}All tests passed successfully!${NC}"
  233. echo -e "${BLUE}Key achievements demonstrated:${NC}"
  234. echo -e " 🚀 RDMA fast path working with mock operations"
  235. echo -e " 🔄 Automatic HTTP fallback when RDMA unavailable"
  236. echo -e " 📊 Performance monitoring and benchmarking"
  237. echo -e " 🛡️ Robust error handling and graceful degradation"
  238. echo -e " 🔌 Complete IPC protocol between Go and Rust"
  239. echo -e " ⚡ Session management with proper cleanup"
  240. print_success "SeaweedFS RDMA integration is ready for hardware deployment!"
  241. # Keep server running for manual testing
  242. echo -e "\n${YELLOW}Demo server will continue running for manual testing...${NC}"
  243. echo -e "${YELLOW}Press Ctrl+C to shutdown.${NC}"
  244. # Wait for user interrupt
  245. wait
  246. }
  247. # Run the main function
  248. main "$@"