aboutsummaryrefslogtreecommitdiff
path: root/seaweedfs-rdma-sidecar/scripts/demo-e2e.sh
blob: 54a751e5798d12f652751c9017abd0e05e2be553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash

# SeaweedFS RDMA End-to-End Demo Script
# This script demonstrates the complete integration between SeaweedFS and the RDMA sidecar

set -e

# Configuration
RDMA_ENGINE_SOCKET="/tmp/rdma-engine.sock"
DEMO_SERVER_PORT=8080
RUST_ENGINE_PID=""
DEMO_SERVER_PID=""

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color

print_header() {
    echo -e "\n${PURPLE}===============================================${NC}"
    echo -e "${PURPLE}$1${NC}"
    echo -e "${PURPLE}===============================================${NC}\n"
}

print_step() {
    echo -e "${CYAN}🔵 $1${NC}"
}

print_success() {
    echo -e "${GREEN}$1${NC}"
}

print_warning() {
    echo -e "${YELLOW}⚠️  $1${NC}"
}

print_error() {
    echo -e "${RED}$1${NC}"
}

cleanup() {
    print_header "CLEANUP"
    
    if [[ -n "$DEMO_SERVER_PID" ]]; then
        print_step "Stopping demo server (PID: $DEMO_SERVER_PID)"
        kill $DEMO_SERVER_PID 2>/dev/null || true
        wait $DEMO_SERVER_PID 2>/dev/null || true
    fi
    
    if [[ -n "$RUST_ENGINE_PID" ]]; then
        print_step "Stopping Rust RDMA engine (PID: $RUST_ENGINE_PID)"
        kill $RUST_ENGINE_PID 2>/dev/null || true
        wait $RUST_ENGINE_PID 2>/dev/null || true
    fi
    
    # Clean up socket
    rm -f "$RDMA_ENGINE_SOCKET"
    
    print_success "Cleanup complete"
}

# Set up cleanup on exit
trap cleanup EXIT

build_components() {
    print_header "BUILDING COMPONENTS"
    
    print_step "Building Go components..."
    go build -o bin/demo-server ./cmd/demo-server
    go build -o bin/test-rdma ./cmd/test-rdma
    go build -o bin/sidecar ./cmd/sidecar
    print_success "Go components built"
    
    print_step "Building Rust RDMA engine..."
    cd rdma-engine
    cargo build --release
    cd ..
    print_success "Rust RDMA engine built"
}

start_rdma_engine() {
    print_header "STARTING RDMA ENGINE"
    
    print_step "Starting Rust RDMA engine..."
    ./rdma-engine/target/release/rdma-engine-server --debug &
    RUST_ENGINE_PID=$!
    
    # Wait for engine to be ready
    print_step "Waiting for RDMA engine to be ready..."
    for i in {1..10}; do
        if [[ -S "$RDMA_ENGINE_SOCKET" ]]; then
            print_success "RDMA engine ready (PID: $RUST_ENGINE_PID)"
            return 0
        fi
        sleep 1
    done
    
    print_error "RDMA engine failed to start"
    exit 1
}

start_demo_server() {
    print_header "STARTING DEMO SERVER"
    
    print_step "Starting SeaweedFS RDMA demo server..."
    ./bin/demo-server --port $DEMO_SERVER_PORT --rdma-socket "$RDMA_ENGINE_SOCKET" --enable-rdma --debug &
    DEMO_SERVER_PID=$!
    
    # Wait for server to be ready
    print_step "Waiting for demo server to be ready..."
    for i in {1..10}; do
        if curl -s "http://localhost:$DEMO_SERVER_PORT/health" > /dev/null 2>&1; then
            print_success "Demo server ready (PID: $DEMO_SERVER_PID)"
            return 0
        fi
        sleep 1
    done
    
    print_error "Demo server failed to start"
    exit 1
}

test_health_check() {
    print_header "HEALTH CHECK TEST"
    
    print_step "Testing health endpoint..."
    response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/health")
    
    if echo "$response" | jq -e '.status == "healthy"' > /dev/null; then
        print_success "Health check passed"
        echo "$response" | jq '.'
    else
        print_error "Health check failed"
        echo "$response"
        exit 1
    fi
}

test_capabilities() {
    print_header "CAPABILITIES TEST"
    
    print_step "Testing capabilities endpoint..."
    response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/stats")
    
    if echo "$response" | jq -e '.enabled == true' > /dev/null; then
        print_success "RDMA capabilities retrieved"
        echo "$response" | jq '.'
    else
        print_warning "RDMA not enabled, but HTTP fallback available"
        echo "$response" | jq '.'
    fi
}

test_needle_read() {
    print_header "NEEDLE READ TEST"
    
    print_step "Testing RDMA needle read..."
    response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/read?volume=1&needle=12345&cookie=305419896&size=1024")
    
    if echo "$response" | jq -e '.success == true' > /dev/null; then
        is_rdma=$(echo "$response" | jq -r '.is_rdma')
        source=$(echo "$response" | jq -r '.source')
        duration=$(echo "$response" | jq -r '.duration')
        data_size=$(echo "$response" | jq -r '.data_size')
        
        if [[ "$is_rdma" == "true" ]]; then
            print_success "RDMA fast path used! Duration: $duration, Size: $data_size bytes"
        else
            print_warning "HTTP fallback used. Duration: $duration, Size: $data_size bytes"
        fi
        
        echo "$response" | jq '.'
    else
        print_error "Needle read failed"
        echo "$response"
        exit 1
    fi
}

test_benchmark() {
    print_header "PERFORMANCE BENCHMARK"
    
    print_step "Running performance benchmark..."
    response=$(curl -s "http://localhost:$DEMO_SERVER_PORT/benchmark?iterations=5&size=2048")
    
    if echo "$response" | jq -e '.benchmark_results' > /dev/null; then
        rdma_ops=$(echo "$response" | jq -r '.benchmark_results.rdma_ops')
        http_ops=$(echo "$response" | jq -r '.benchmark_results.http_ops')
        avg_latency=$(echo "$response" | jq -r '.benchmark_results.avg_latency')
        throughput=$(echo "$response" | jq -r '.benchmark_results.throughput_mbps')
        ops_per_sec=$(echo "$response" | jq -r '.benchmark_results.ops_per_sec')
        
        print_success "Benchmark completed:"
        echo -e "  ${BLUE}RDMA Operations:${NC} $rdma_ops"
        echo -e "  ${BLUE}HTTP Operations:${NC} $http_ops"
        echo -e "  ${BLUE}Average Latency:${NC} $avg_latency"
        echo -e "  ${BLUE}Throughput:${NC} $throughput MB/s"
        echo -e "  ${BLUE}Operations/sec:${NC} $ops_per_sec"
        
        echo -e "\n${BLUE}Full benchmark results:${NC}"
        echo "$response" | jq '.benchmark_results'
    else
        print_error "Benchmark failed"
        echo "$response"
        exit 1
    fi
}

test_direct_rdma() {
    print_header "DIRECT RDMA ENGINE TEST"
    
    print_step "Testing direct RDMA engine communication..."
    
    echo "Testing ping..."
    ./bin/test-rdma ping 2>/dev/null && print_success "Direct RDMA ping successful" || print_warning "Direct RDMA ping failed"
    
    echo -e "\nTesting capabilities..."
    ./bin/test-rdma capabilities 2>/dev/null | head -15 && print_success "Direct RDMA capabilities successful" || print_warning "Direct RDMA capabilities failed"
    
    echo -e "\nTesting direct read..."
    ./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"
}

show_demo_urls() {
    print_header "DEMO SERVER INFORMATION"
    
    echo -e "${GREEN}🌐 Demo server is running at: http://localhost:$DEMO_SERVER_PORT${NC}"
    echo -e "${GREEN}📱 Try these URLs:${NC}"
    echo -e "  ${BLUE}Home page:${NC}          http://localhost:$DEMO_SERVER_PORT/"
    echo -e "  ${BLUE}Health check:${NC}       http://localhost:$DEMO_SERVER_PORT/health"
    echo -e "  ${BLUE}Statistics:${NC}         http://localhost:$DEMO_SERVER_PORT/stats"
    echo -e "  ${BLUE}Read needle:${NC}        http://localhost:$DEMO_SERVER_PORT/read?volume=1&needle=12345&cookie=305419896&size=1024"
    echo -e "  ${BLUE}Benchmark:${NC}          http://localhost:$DEMO_SERVER_PORT/benchmark?iterations=5&size=2048"
    
    echo -e "\n${GREEN}📋 Example curl commands:${NC}"
    echo -e "  ${CYAN}curl \"http://localhost:$DEMO_SERVER_PORT/health\" | jq '.'${NC}"
    echo -e "  ${CYAN}curl \"http://localhost:$DEMO_SERVER_PORT/read?volume=1&needle=12345&size=1024\" | jq '.'${NC}"
    echo -e "  ${CYAN}curl \"http://localhost:$DEMO_SERVER_PORT/benchmark?iterations=10\" | jq '.benchmark_results'${NC}"
}

interactive_mode() {
    print_header "INTERACTIVE MODE"
    
    show_demo_urls
    
    echo -e "\n${YELLOW}Press Enter to run automated tests, or Ctrl+C to exit and explore manually...${NC}"
    read -r
}

main() {
    print_header "🚀 SEAWEEDFS RDMA END-TO-END DEMO"
    
    echo -e "${GREEN}This demonstration shows:${NC}"
    echo -e "  ✅ Complete Go ↔ Rust IPC integration"
    echo -e "  ✅ SeaweedFS RDMA client with HTTP fallback" 
    echo -e "  ✅ High-performance needle reads via RDMA"
    echo -e "  ✅ Performance benchmarking capabilities"
    echo -e "  ✅ Production-ready error handling and logging"
    
    # Check dependencies
    if ! command -v jq &> /dev/null; then
        print_error "jq is required for this demo. Please install it: brew install jq"
        exit 1
    fi
    
    if ! command -v curl &> /dev/null; then
        print_error "curl is required for this demo."
        exit 1
    fi
    
    # Build and start components
    build_components
    start_rdma_engine
    sleep 2  # Give engine time to fully initialize
    start_demo_server
    sleep 2  # Give server time to connect to engine
    
    # Show interactive information
    interactive_mode
    
    # Run automated tests
    test_health_check
    test_capabilities
    test_needle_read
    test_benchmark
    test_direct_rdma
    
    print_header "🎉 END-TO-END DEMO COMPLETE!"
    
    echo -e "${GREEN}All tests passed successfully!${NC}"
    echo -e "${BLUE}Key achievements demonstrated:${NC}"
    echo -e "  🚀 RDMA fast path working with mock operations"
    echo -e "  🔄 Automatic HTTP fallback when RDMA unavailable"
    echo -e "  📊 Performance monitoring and benchmarking"
    echo -e "  🛡️  Robust error handling and graceful degradation"
    echo -e "  🔌 Complete IPC protocol between Go and Rust"
    echo -e "  ⚡ Session management with proper cleanup"
    
    print_success "SeaweedFS RDMA integration is ready for hardware deployment!"
    
    # Keep server running for manual testing
    echo -e "\n${YELLOW}Demo server will continue running for manual testing...${NC}"
    echo -e "${YELLOW}Press Ctrl+C to shutdown.${NC}"
    
    # Wait for user interrupt
    wait
}

# Run the main function
main "$@"