# Check current CPU usage
docker stats nova-backend --no-stream
# System-wide CPU
top -bn1 | head -20
# Per-process CPU
ps aux --sort=-%cpu | head -10
# Inside container
docker exec -it nova-backend top -bn1
# Node.js process details
docker exec -it nova-backend ps aux | grep node
# Recent logs
docker logs nova-backend --tail 200 --follow
# Look for infinite loops or heavy operations
docker logs nova-backend 2>&1 | grep -i "processing\|computing\|calculating"
# Generate CPU profile (if profiling enabled)
docker exec -it nova-backend node --prof server.js
# Or use clinic.js
docker exec -it nova-backend clinic doctor -- node server.js
Symptoms: Single process consuming 100% CPU
Solution:
# Identify the problematic code from logs
# Restart service immediately
docker restart nova-backend
# Deploy hotfix to resolve infinite loop
Symptoms: CPU spikes during specific operations
Solution:
# Identify expensive operations
# Move to background job queue
# Optimize algorithm
# Add caching
Symptoms: CPU increases with request rate
Solution:
# Scale horizontally
docker-compose up -d --scale backend=3
# Or on AWS
aws autoscaling set-desired-capacity \
--auto-scaling-group-name nova-rewards-asg \
--desired-capacity 4
# Enable rate limiting
# Optimize hot paths
Symptoms: High CPU with increasing memory
Solution:
# Check memory usage
docker stats nova-backend
# Restart to free memory
docker restart nova-backend
# Investigate memory leak
# Take heap snapshot for analysis
Symptoms: CPU high during database operations
Solution:
# Check slow queries
docker exec -it nova-postgres psql -U nova -d nova_rewards -c "
SELECT query, calls, total_time, mean_time
FROM pg_stat_statements
ORDER BY mean_time DESC
LIMIT 10;"
# Optimize queries
# Add indexes
# Use query result caching
# Add more instances
docker-compose up -d --scale backend=4
// Reduce rate limits temporarily
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 50 // Reduce from 100
});
# Disable background jobs temporarily
# Disable analytics
# Reduce logging verbosity