demo-mount-rdma.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #!/bin/bash
  2. set -euo pipefail
  3. # Colors for output
  4. RED='\033[0;31m'
  5. GREEN='\033[0;32m'
  6. BLUE='\033[0;34m'
  7. YELLOW='\033[1;33m'
  8. NC='\033[0m' # No Color
  9. # Configuration - assumes script is run from seaweedfs-rdma-sidecar directory
  10. SEAWEEDFS_DIR="$(realpath ..)"
  11. SIDECAR_DIR="$(pwd)"
  12. MOUNT_POINT="/tmp/seaweedfs-rdma-mount"
  13. FILER_ADDR="localhost:8888"
  14. SIDECAR_ADDR="localhost:8081"
  15. # PIDs for cleanup
  16. MASTER_PID=""
  17. VOLUME_PID=""
  18. FILER_PID=""
  19. SIDECAR_PID=""
  20. MOUNT_PID=""
  21. cleanup() {
  22. echo -e "\n${YELLOW}🧹 Cleaning up processes...${NC}"
  23. # Unmount filesystem
  24. if mountpoint -q "$MOUNT_POINT" 2>/dev/null; then
  25. echo "📤 Unmounting $MOUNT_POINT..."
  26. fusermount -u "$MOUNT_POINT" 2>/dev/null || umount "$MOUNT_POINT" 2>/dev/null || true
  27. sleep 1
  28. fi
  29. # Kill processes
  30. for pid in $MOUNT_PID $SIDECAR_PID $FILER_PID $VOLUME_PID $MASTER_PID; do
  31. if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
  32. echo "🔪 Killing process $pid..."
  33. kill "$pid" 2>/dev/null || true
  34. fi
  35. done
  36. # Wait for processes to exit
  37. sleep 2
  38. # Force kill if necessary
  39. for pid in $MOUNT_PID $SIDECAR_PID $FILER_PID $VOLUME_PID $MASTER_PID; do
  40. if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
  41. echo "💀 Force killing process $pid..."
  42. kill -9 "$pid" 2>/dev/null || true
  43. fi
  44. done
  45. # Clean up mount point
  46. if [[ -d "$MOUNT_POINT" ]]; then
  47. rmdir "$MOUNT_POINT" 2>/dev/null || true
  48. fi
  49. echo -e "${GREEN}✅ Cleanup complete${NC}"
  50. }
  51. trap cleanup EXIT
  52. wait_for_service() {
  53. local name=$1
  54. local url=$2
  55. local max_attempts=30
  56. local attempt=1
  57. echo -e "${BLUE}⏳ Waiting for $name to be ready...${NC}"
  58. while [[ $attempt -le $max_attempts ]]; do
  59. if curl -s "$url" >/dev/null 2>&1; then
  60. echo -e "${GREEN}✅ $name is ready${NC}"
  61. return 0
  62. fi
  63. echo " Attempt $attempt/$max_attempts..."
  64. sleep 1
  65. ((attempt++))
  66. done
  67. echo -e "${RED}❌ $name failed to start within $max_attempts seconds${NC}"
  68. return 1
  69. }
  70. echo -e "${BLUE}🚀 SEAWEEDFS RDMA MOUNT DEMONSTRATION${NC}"
  71. echo "======================================"
  72. echo ""
  73. echo "This demo shows SeaweedFS mount with RDMA acceleration:"
  74. echo " • Standard SeaweedFS cluster (master, volume, filer)"
  75. echo " • RDMA sidecar for acceleration"
  76. echo " • FUSE mount with RDMA fast path"
  77. echo " • Performance comparison tests"
  78. echo ""
  79. # Create mount point
  80. echo -e "${BLUE}📁 Creating mount point: $MOUNT_POINT${NC}"
  81. mkdir -p "$MOUNT_POINT"
  82. # Start SeaweedFS Master
  83. echo -e "${BLUE}🎯 Starting SeaweedFS Master...${NC}"
  84. cd "$SEAWEEDFS_DIR"
  85. ./weed master -port=9333 -mdir=/tmp/seaweedfs-master &
  86. MASTER_PID=$!
  87. wait_for_service "Master" "http://localhost:9333/cluster/status"
  88. # Start SeaweedFS Volume Server
  89. echo -e "${BLUE}💾 Starting SeaweedFS Volume Server...${NC}"
  90. ./weed volume -mserver=localhost:9333 -port=8080 -dir=/tmp/seaweedfs-volume &
  91. VOLUME_PID=$!
  92. wait_for_service "Volume Server" "http://localhost:8080/status"
  93. # Start SeaweedFS Filer
  94. echo -e "${BLUE}📂 Starting SeaweedFS Filer...${NC}"
  95. ./weed filer -master=localhost:9333 -port=8888 &
  96. FILER_PID=$!
  97. wait_for_service "Filer" "http://localhost:8888/"
  98. # Start RDMA Sidecar
  99. echo -e "${BLUE}⚡ Starting RDMA Sidecar...${NC}"
  100. cd "$SIDECAR_DIR"
  101. ./bin/demo-server --port 8081 --rdma-socket /tmp/rdma-engine.sock --volume-server-url http://localhost:8080 --enable-rdma --debug &
  102. SIDECAR_PID=$!
  103. wait_for_service "RDMA Sidecar" "http://localhost:8081/health"
  104. # Check RDMA capabilities
  105. echo -e "${BLUE}🔍 Checking RDMA capabilities...${NC}"
  106. curl -s "http://localhost:8081/stats" | jq . || curl -s "http://localhost:8081/stats"
  107. echo ""
  108. echo -e "${BLUE}🗂️ Mounting SeaweedFS with RDMA acceleration...${NC}"
  109. # Mount with RDMA acceleration
  110. cd "$SEAWEEDFS_DIR"
  111. ./weed mount \
  112. -filer="$FILER_ADDR" \
  113. -dir="$MOUNT_POINT" \
  114. -rdma.enabled=true \
  115. -rdma.sidecar="$SIDECAR_ADDR" \
  116. -rdma.fallback=true \
  117. -rdma.maxConcurrent=64 \
  118. -rdma.timeoutMs=5000 \
  119. -debug=true &
  120. MOUNT_PID=$!
  121. # Wait for mount to be ready
  122. echo -e "${BLUE}⏳ Waiting for mount to be ready...${NC}"
  123. sleep 5
  124. # Check if mount is successful
  125. if ! mountpoint -q "$MOUNT_POINT"; then
  126. echo -e "${RED}❌ Mount failed${NC}"
  127. exit 1
  128. fi
  129. echo -e "${GREEN}✅ SeaweedFS mounted successfully with RDMA acceleration!${NC}"
  130. echo ""
  131. # Demonstrate RDMA-accelerated operations
  132. echo -e "${BLUE}🧪 TESTING RDMA-ACCELERATED FILE OPERATIONS${NC}"
  133. echo "=============================================="
  134. # Create test files
  135. echo -e "${BLUE}📝 Creating test files...${NC}"
  136. echo "Hello, RDMA World!" > "$MOUNT_POINT/test1.txt"
  137. echo "This file will be read via RDMA acceleration!" > "$MOUNT_POINT/test2.txt"
  138. # Create a larger test file
  139. echo -e "${BLUE}📝 Creating larger test file (1MB)...${NC}"
  140. dd if=/dev/zero of="$MOUNT_POINT/large_test.dat" bs=1024 count=1024 2>/dev/null
  141. echo -e "${GREEN}✅ Test files created${NC}"
  142. echo ""
  143. # Test file reads
  144. echo -e "${BLUE}📖 Testing file reads (should use RDMA fast path)...${NC}"
  145. echo ""
  146. echo "📄 Reading test1.txt:"
  147. cat "$MOUNT_POINT/test1.txt"
  148. echo ""
  149. echo "📄 Reading test2.txt:"
  150. cat "$MOUNT_POINT/test2.txt"
  151. echo ""
  152. echo "📄 Reading first 100 bytes of large file:"
  153. head -c 100 "$MOUNT_POINT/large_test.dat" | hexdump -C | head -5
  154. echo ""
  155. # Performance test
  156. echo -e "${BLUE}🏁 PERFORMANCE COMPARISON${NC}"
  157. echo "========================="
  158. echo "🔥 Testing read performance with RDMA acceleration..."
  159. time_start=$(date +%s%N)
  160. for i in {1..10}; do
  161. cat "$MOUNT_POINT/large_test.dat" > /dev/null
  162. done
  163. time_end=$(date +%s%N)
  164. rdma_time=$((($time_end - $time_start) / 1000000)) # Convert to milliseconds
  165. echo "✅ RDMA-accelerated reads: 10 x 1MB file = ${rdma_time}ms total"
  166. echo ""
  167. # Check RDMA statistics
  168. echo -e "${BLUE}📊 RDMA Statistics:${NC}"
  169. curl -s "http://localhost:8081/stats" | jq . 2>/dev/null || curl -s "http://localhost:8081/stats"
  170. echo ""
  171. # List files
  172. echo -e "${BLUE}📋 Files in mounted filesystem:${NC}"
  173. ls -la "$MOUNT_POINT/"
  174. echo ""
  175. # Interactive mode
  176. echo -e "${BLUE}🎮 INTERACTIVE MODE${NC}"
  177. echo "=================="
  178. echo ""
  179. echo "The SeaweedFS filesystem is now mounted at: $MOUNT_POINT"
  180. echo "RDMA acceleration is active for all read operations!"
  181. echo ""
  182. echo "Try these commands:"
  183. echo " ls $MOUNT_POINT/"
  184. echo " cat $MOUNT_POINT/test1.txt"
  185. echo " echo 'New content' > $MOUNT_POINT/new_file.txt"
  186. echo " cat $MOUNT_POINT/new_file.txt"
  187. echo ""
  188. echo "Monitor RDMA stats: curl http://localhost:8081/stats | jq"
  189. echo "Check mount status: mount | grep seaweedfs"
  190. echo ""
  191. echo -e "${YELLOW}Press Ctrl+C to stop the demo and cleanup${NC}"
  192. # Keep running until interrupted
  193. while true; do
  194. sleep 5
  195. # Check if mount is still active
  196. if ! mountpoint -q "$MOUNT_POINT"; then
  197. echo -e "${RED}❌ Mount point lost, exiting...${NC}"
  198. break
  199. fi
  200. # Show periodic stats
  201. echo -e "${BLUE}📊 Current RDMA stats ($(date)):${NC}"
  202. curl -s "http://localhost:8081/stats" | jq '.rdma_enabled, .total_reads, .rdma_reads, .http_fallbacks' 2>/dev/null || echo "Stats unavailable"
  203. echo ""
  204. done