-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-memory-optimized.sh
More file actions
91 lines (75 loc) · 3.27 KB
/
start-memory-optimized.sh
File metadata and controls
91 lines (75 loc) · 3.27 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
#!/bin/bash
# Memory-Optimized PulseEvents Startup Script
# This script starts the application with aggressive memory optimization
# Target: 512MB total memory usage
echo "🚀 Starting PulseEvents with Memory Optimization..."
echo "📊 Target Total Memory: 512MB"
echo ""
# Check if Docker is running
if ! docker info >/dev/null 2>&1; then
echo "❌ Docker is not running. Please start Docker first."
exit 1
fi
# Set memory optimization profile
export SPRING_PROFILES_ACTIVE=docker,memory-optimized
# Set JWT secret if not already set
if [ -z "$JWT_SECRET" ]; then
export JWT_SECRET="your-super-secret-jwt-key-that-is-at-least-256-bits-long-for-hmac-sha256"
echo "⚠️ Using default JWT secret. Set JWT_SECRET environment variable for production."
fi
# Check available system memory
AVAILABLE_MEMORY=$(free -m | awk 'NR==2{printf "%.0f", $7}')
echo "💾 Available System Memory: ${AVAILABLE_MEMORY}MB"
if [ "$AVAILABLE_MEMORY" -lt 1024 ]; then
echo "⚠️ WARNING: Low system memory detected. This setup requires at least 1GB of available memory."
echo " Consider stopping other applications or increasing system memory."
fi
echo ""
echo "📋 Memory Allocation Plan:"
echo " • PostgreSQL: 64MB (limit)"
echo " • Discovery Server: 80MB (limit)"
echo " • Config Server: 80MB (limit)"
echo " • Auth Service: 96MB (limit)"
echo " • Event Service: 96MB (limit)"
echo " • Booking Service: 96MB (limit)"
echo " • API Gateway: 80MB (limit)"
echo " • Frontend: 16MB (limit)"
echo " ═══════════════════════════════"
echo " • TOTAL: 608MB (with safety margin)"
echo ""
# Stop any existing containers
echo "🛑 Stopping existing containers..."
docker-compose -f docker-compose.yml down --remove-orphans 2>/dev/null || true
docker-compose -f docker-compose.memory-optimized.yml down --remove-orphans 2>/dev/null || true
# Start with memory-optimized configuration
echo "🏗️ Building and starting memory-optimized containers..."
docker-compose -f docker-compose.memory-optimized.yml up --build -d
# Wait for services to start
echo "⏳ Waiting for services to start..."
sleep 30
# Check service health
echo ""
echo "🔍 Checking service health..."
services=("discovery-server:8761" "config-server:8888" "authentication-service:8091" "event-service:8082" "booking-service:8083" "api-gateway:8080" "frontend:5173")
for service in "${services[@]}"; do
IFS=':' read -r name port <<< "$service"
if curl -f -s http://localhost:$port/actuator/health >/dev/null 2>&1 || curl -f -s http://localhost:$port/ >/dev/null 2>&1; then
echo "✅ $name is healthy"
else
echo "❌ $name is not responding"
fi
done
echo ""
echo "📊 Current Memory Usage:"
docker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}"
echo ""
echo "🎉 Memory-optimized PulseEvents is starting!"
echo "🌐 Access the application at: http://localhost:5173"
echo "📊 Monitor memory usage with: docker stats"
echo ""
echo "💡 Tips for further optimization:"
echo " • Monitor memory usage regularly"
echo " • Adjust JVM heap sizes if needed"
echo " • Consider using Alpine-based images"
echo " • Profile application under load"
echo ""