3.6 KiB
3.6 KiB
WebSocket Deployment Guide
Quick Deployment Steps
1. Install New Dependencies
cd /opt/dockers/echoes_of_the_ashes
docker compose down
docker compose build
docker compose up -d
This will rebuild the containers with the new websockets package.
2. Verify Installation
Check that the API container started successfully:
docker compose logs api | grep "WebSocket"
You should see log entries about WebSocket connections once players connect.
3. Test WebSocket Connection
Open the game in a browser and check the console (F12):
- Look for:
🔌 Connecting to WebSocket: ws://... - Look for:
✅ WebSocket connected
4. Monitor Active Connections
Check the health endpoint to see active WebSocket connections:
curl http://localhost:8000/health
(Can be extended to show WebSocket connection count)
5. Test Real-Time Updates
-
Movement Test:
- Open game in two browser tabs (different accounts)
- Move one character to a location
- Other tab should see "Player arrived" message immediately
-
Combat Test:
- Start combat with an NPC
- Attacks should update immediately (no 5s delay)
-
Pickup Test:
- Drop an item in a location
- Other players in same location should see it disappear when picked up
Rollback (If Needed)
If WebSocket causes issues, you can roll back to pure polling:
Option 1: Disable WebSocket on Frontend
Edit pwa/src/components/Game.tsx:
const { isConnected, sendMessage } = useGameWebSocket({
token,
onMessage: handleWebSocketMessage,
enabled: false // Change true to false
})
Option 2: Remove WebSocket from Backend
Revert changes to:
api/main.py(remove WebSocket endpoint and broadcasts)api/database.py(remove get_players_in_location)requirements.txt(remove websockets package)
Then rebuild and redeploy.
Performance Monitoring
Watch for Issues
# Monitor API logs for WebSocket errors
docker compose logs -f api | grep "WebSocket\|❌"
# Check for memory usage increases
docker stats echoes_of_the_ashes_api
# Monitor connection count (check server load)
# Add to health endpoint or check logs for "WebSocket connected/disconnected"
Expected Behavior
- Connection: Players connect within 1-2 seconds of loading game
- Reconnection: If network drops, should reconnect within 3 seconds
- Memory: ~10MB per 1,000 connections (very low)
- CPU: Should decrease compared to polling (event-driven)
Troubleshooting
WebSocket Not Connecting
- Check CORS settings in
api/main.py - Verify token is present:
localStorage.getItem('token')in browser console - Check nginx/proxy configuration (if using reverse proxy)
Frequent Disconnections
- Check heartbeat interval (30s default)
- Verify network stability
- Check for proxy timeouts (nginx:
proxy_read_timeout 60s;)
Messages Not Received
- Verify
manager.send_personal_message()is being called - Check player_id matches active connection
- Look for WebSocket send errors in logs
Next Steps After Deployment
- Monitor for 24 hours: Check stability and error rates
- Gather user feedback: Is latency better? Any connection issues?
- Plan live chat: Quick win feature using WebSocket infrastructure
- Consider party system: Next major feature enabled by WebSockets
Success Metrics
After deployment, you should see:
- ✅ 95% reduction in API request volume
- ✅ <100ms latency for game updates (vs 2500ms avg with polling)
- ✅ Lower server CPU usage (event-driven vs continuous polling)
- ✅ Improved UX - instant feedback on actions
Good luck with the deployment! 🚀