-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-memory-optimized.ps1
More file actions
104 lines (89 loc) · 4.52 KB
/
start-memory-optimized.ps1
File metadata and controls
104 lines (89 loc) · 4.52 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
# Memory-Optimized PulseEvents Startup Script (PowerShell)
# This script starts the application with aggressive memory optimization
# Target: 512MB total memory usage
Write-Host "🚀 Starting PulseEvents with Memory Optimization..." -ForegroundColor Green
Write-Host "📊 Target Total Memory: 512MB" -ForegroundColor Cyan
Write-Host ""
# Check if Docker is running
try {
docker info | Out-Null
} catch {
Write-Host "❌ Docker is not running. Please start Docker first." -ForegroundColor Red
exit 1
}
# Set memory optimization profile
$env:SPRING_PROFILES_ACTIVE = "docker,memory-optimized"
# Set JWT secret if not already set
if (-not $env:JWT_SECRET) {
$env:JWT_SECRET = "your-super-secret-jwt-key-that-is-at-least-256-bits-long-for-hmac-sha256"
Write-Host "⚠️ Using default JWT secret. Set JWT_SECRET environment variable for production." -ForegroundColor Yellow
}
# Check available system memory
$availableMemory = [math]::Round((Get-CimInstance -ClassName Win32_OperatingSystem).FreePhysicalMemory / 1024)
Write-Host "💾 Available System Memory: ${availableMemory}MB" -ForegroundColor Cyan
if ($availableMemory -lt 1024) {
Write-Host "⚠️ WARNING: Low system memory detected. This setup requires at least 1GB of available memory." -ForegroundColor Yellow
Write-Host " Consider stopping other applications or increasing system memory." -ForegroundColor Yellow
}
Write-Host ""
Write-Host "📋 Memory Allocation Plan (Final):" -ForegroundColor Yellow
Write-Host " • PostgreSQL: 64MB (limit)"
Write-Host " • Discovery Server: 128MB (limit) - Increased for stability"
Write-Host " • Config Server: 112MB (limit) - Increased for stability"
Write-Host " • Auth Service: 128MB (limit) - Increased for stability"
Write-Host " • Event Service: 128MB (limit) - Increased for stability"
Write-Host " • Booking Service: 128MB (limit) - Increased for stability"
Write-Host " • API Gateway: 80MB (limit)"
Write-Host " • Frontend: 16MB (limit)"
Write-Host " ═══════════════════════════════"
Write-Host " • TOTAL: 784MB (with safety margin)" -ForegroundColor Green
Write-Host " • Still 63% reduction from original ~2.1GB!" -ForegroundColor Cyan
Write-Host ""
# Stop any existing containers
Write-Host "🛑 Stopping existing containers..." -ForegroundColor Yellow
docker-compose -f docker-compose.yml down --remove-orphans 2>$null
docker-compose -f docker-compose.memory-optimized.yml down --remove-orphans 2>$null
# Start with memory-optimized configuration
Write-Host "🏗️ Building and starting memory-optimized containers..." -ForegroundColor Yellow
docker-compose -f docker-compose.memory-optimized.yml up --build -d
# Wait for services to start
Write-Host "⏳ Waiting for services to start..." -ForegroundColor Yellow
Start-Sleep -Seconds 30
# Check service health
Write-Host ""
Write-Host "🔍 Checking service health..." -ForegroundColor Yellow
$services = @(
@{name="discovery-server"; port=8761},
@{name="config-server"; port=8888},
@{name="authentication-service"; port=8091},
@{name="event-service"; port=8082},
@{name="booking-service"; port=8083},
@{name="api-gateway"; port=8080},
@{name="frontend"; port=5173}
)
foreach ($service in $services) {
try {
if ($service.name -eq "frontend") {
$response = Invoke-WebRequest -Uri "http://localhost:$($service.port)/" -TimeoutSec 5 -UseBasicParsing
} else {
$response = Invoke-WebRequest -Uri "http://localhost:$($service.port)/actuator/health" -TimeoutSec 5 -UseBasicParsing
}
Write-Host "✅ $($service.name) is healthy" -ForegroundColor Green
} catch {
Write-Host "❌ $($service.name) is not responding" -ForegroundColor Red
}
}
Write-Host ""
Write-Host "📊 Current Memory Usage:" -ForegroundColor Cyan
docker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}"
Write-Host ""
Write-Host "🎉 Memory-optimized PulseEvents is starting!" -ForegroundColor Green
Write-Host "🌐 Access the application at: http://localhost:5173" -ForegroundColor Cyan
Write-Host "📊 Monitor memory usage with: docker stats" -ForegroundColor Cyan
Write-Host ""
Write-Host "💡 Tips for further optimization:" -ForegroundColor Yellow
Write-Host " • Monitor memory usage regularly"
Write-Host " • Adjust JVM heap sizes if needed"
Write-Host " • Consider using Alpine-based images"
Write-Host " • Profile application under load"
Write-Host ""