-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_siege.sh
More file actions
executable file
·258 lines (220 loc) · 7.43 KB
/
Copy pathtest_siege.sh
File metadata and controls
executable file
·258 lines (220 loc) · 7.43 KB
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
#!/bin/bash
# Ensure siege is in PATH
export PATH="$HOME/.local/bin:$PATH"
# Phase 10 - Siege Testing Script
# Tests server stability under load
echo "========================================"
echo "PHASE 10 - SIEGE TESTING"
echo "========================================"
echo ""
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
SERVER="localhost"
PORT="8091"
URL="http://$SERVER:$PORT/test.txt"
# Check if siege is installed
if ! command -v siege &> /dev/null; then
echo -e "${RED}ERROR: siege is not installed${NC}"
echo "Install with: bash install_siege.sh"
exit 1
fi
echo -e "${BLUE}Siege version:${NC}"
siege --version
echo ""
# Check if server is running
echo -e "${YELLOW}Checking if server is running...${NC}"
if ! curl -s --connect-timeout 3 "$URL" > /dev/null 2>&1; then
echo -e "${RED}ERROR: Server is not responding at $URL${NC}"
echo "Start your server first with: make run"
exit 1
fi
echo -e "${GREEN}✓ Server is running${NC}"
echo ""
#
# TEST 1: WARMUP - Light Load
#
echo "========================================"
echo "TEST 1: WARMUP (10 users, 10 seconds)"
echo "========================================"
echo "This is a light load test to verify basic functionality"
echo ""
siege -b -c 100 -t 10S "$URL" 2>&1 | tee /tmp/siege_warmup.log
AVAILABILITY=$(grep "Availability:" /tmp/siege_warmup.log | awk '{print $2}' | tr -d '%')
echo ""
if (( $(echo "$AVAILABILITY >= 99.5" | bc -l) )); then
echo -e "${GREEN}✅ PASS - Warmup availability: $AVAILABILITY%${NC}"
else
echo -e "${RED}❌ FAIL - Warmup availability: $AVAILABILITY% (need 99.5%)${NC}"
echo "Server has issues even under light load!"
fi
echo ""
sleep 2
#
# TEST 2: MODERATE LOAD
#
echo "========================================"
echo "TEST 2: MODERATE LOAD (50 users, 30 sec)"
echo "========================================"
echo "Testing with moderate concurrent users"
echo ""
siege -b -c 50 -t 30S "$URL" 2>&1 | tee /tmp/siege_moderate.log
AVAILABILITY=$(grep "Availability:" /tmp/siege_moderate.log | awk '{print $2}' | tr -d '%')
echo ""
if (( $(echo "$AVAILABILITY >= 99.5" | bc -l) )); then
echo -e "${GREEN}✅ PASS - Moderate load availability: $AVAILABILITY%${NC}"
else
echo -e "${RED}❌ FAIL - Moderate load availability: $AVAILABILITY% (need 99.5%)${NC}"
fi
echo ""
sleep 2
#
# TEST 3: HEAVY LOAD (AUDIT REQUIREMENT)
#
echo "========================================"
echo "TEST 3: HEAVY LOAD (100 users, 1 minute)"
echo "========================================"
echo "This simulates the audit stress test"
echo ""
siege -b -c 100 -t 1M "$URL" 2>&1 | tee /tmp/siege_heavy.log
echo ""
echo "========================================"
echo "HEAVY LOAD RESULTS:"
echo "========================================"
AVAILABILITY=$(grep "Availability:" /tmp/siege_heavy.log | awk '{print $2}' | tr -d '%')
FAILED=$(grep "Failed transactions:" /tmp/siege_heavy.log | awk '{print $3}')
RESPONSE_TIME=$(grep "Response time:" /tmp/siege_heavy.log | awk '{print $3}')
TRANSACTION_RATE=$(grep "Transaction rate:" /tmp/siege_heavy.log | awk '{print $3}')
echo "Availability: $AVAILABILITY%"
echo "Failed: $FAILED transactions"
echo "Response Time: $RESPONSE_TIME seconds"
echo "Transaction Rate: $TRANSACTION_RATE trans/sec"
echo ""
if (( $(echo "$AVAILABILITY >= 99.5" | bc -l) )); then
echo -e "${GREEN}✅ PASS - Heavy load availability: $AVAILABILITY%${NC}"
HEAVY_PASS=1
else
echo -e "${RED}❌ FAIL - Heavy load availability: $AVAILABILITY% (need 99.5%)${NC}"
HEAVY_PASS=0
fi
echo ""
sleep 2
#
# TEST 4: CONNECTION CLEANUP CHECK
#
echo "========================================"
echo "TEST 4: CONNECTION CLEANUP"
echo "========================================"
echo "Checking for hanging connections..."
echo ""
# Wait a bit for connections to close
sleep 3
# Check for established connections
CONNECTIONS=$(netstat -an 2>/dev/null | grep ":$PORT" | grep ESTABLISHED | wc -l)
echo "Active connections to port $PORT: $CONNECTIONS"
if [ "$CONNECTIONS" -eq 0 ]; then
echo -e "${GREEN}✅ PASS - No hanging connections${NC}"
CLEANUP_PASS=1
else
echo -e "${YELLOW}⚠️ WARNING - $CONNECTIONS connections still active${NC}"
echo "They might be keep-alive connections (OK) or hanging (BAD)"
echo ""
echo "Connection details:"
netstat -an 2>/dev/null | grep ":$PORT" | grep ESTABLISHED
CLEANUP_PASS=0
fi
echo ""
#
# TEST 5: MEMORY LEAK CHECK
#
echo "========================================"
echo "TEST 5: MEMORY LEAK CHECK"
echo "========================================"
echo "Running extended test to check for memory leaks..."
echo ""
# Get Java process PID
JAVA_PID=$(pgrep -f "java Main" | head -1)
if [ -z "$JAVA_PID" ]; then
echo -e "${YELLOW}⚠️ Could not find Java process${NC}"
MEMORY_PASS=0
else
# Get initial memory (RSS in KB)
INITIAL_MEM=$(ps -p $JAVA_PID -o rss= | tr -d ' ')
echo "Initial memory: $INITIAL_MEM KB (PID: $JAVA_PID)"
# Run 2-minute stress test
echo "Running 1-minute stress test..."
siege -b -c 50 -t 1M "$URL" > /dev/null 2>&1
# Wait for cleanup
sleep 5
# Check if process still exists
if ! ps -p $JAVA_PID > /dev/null 2>&1; then
echo -e "${RED}❌ FAIL - Server crashed during stress test!${NC}"
MEMORY_PASS=0
else
# Get final memory
FINAL_MEM=$(ps -p $JAVA_PID -o rss= | tr -d ' ')
echo "Final memory: $FINAL_MEM KB"
# Calculate increase
INCREASE=$((FINAL_MEM - INITIAL_MEM))
# Avoid division by zero
if [ $INITIAL_MEM -eq 0 ]; then
echo -e "${YELLOW}⚠️ Could not measure memory${NC}"
MEMORY_PASS=0
else
PERCENT=$((INCREASE * 100 / INITIAL_MEM))
echo "Memory increase: $INCREASE KB ($PERCENT%)"
echo ""
if [ $PERCENT -lt 20 ]; then
echo -e "${GREEN}✅ PASS - Memory stable (< 20% increase)${NC}"
MEMORY_PASS=1
else
echo -e "${YELLOW}⚠️ WARNING - Memory increased by $PERCENT%${NC}"
echo "This could indicate a memory leak"
MEMORY_PASS=0
fi
fi
fi
fi
echo ""
#
# FINAL RESULTS
#
echo "========================================"
echo "PHASE 10 - FINAL RESULTS"
echo "========================================"
echo ""
if [ $HEAVY_PASS -eq 1 ] && [ $CLEANUP_PASS -eq 1 ]; then
echo -e "${GREEN}🎉 SUCCESS! ALL CRITICAL TESTS PASSED! 🎉${NC}"
echo ""
echo "✅ Availability ≥ 99.5%"
echo "✅ No hanging connections"
echo "✅ Server stable under load"
echo ""
echo -e "${GREEN}YOUR SERVER IS AUDIT-READY!${NC}"
exit 0
else
echo -e "${RED}❌ SOME TESTS FAILED${NC}"
echo ""
if [ $HEAVY_PASS -eq 0 ]; then
echo "❌ Availability < 99.5%"
echo " Possible issues:"
echo " - Connections not closing properly"
echo " - Request timeout too aggressive"
echo " - Keep-alive not working correctly"
echo " - Server crashing under load"
fi
if [ $CLEANUP_PASS -eq 0 ]; then
echo "❌ Hanging connections detected"
echo " Possible issues:"
echo " - Keep-alive timeout too long"
echo " - Connections not cleaned up in closeConnection()"
echo " - File descriptors leaking"
fi
echo ""
echo "TROUBLESHOOT for fixes"
echo ""
exit 1
fi