# Production Deployment Guide This guide covers deploying Talk2Me in a production environment using a proper WSGI server. ## Overview The Flask development server is not suitable for production use. This guide covers: - Gunicorn as the WSGI server - Nginx as a reverse proxy - Docker for containerization - Systemd for process management - Security best practices ## Quick Start with Docker ### 1. Using Docker Compose ```bash # Clone the repository git clone https://github.com/your-repo/talk2me.git cd talk2me # Create .env file with production settings cat > .env < backup.sql # Redis redis-cli BGSAVE ``` ### Application Backup ```bash # Backup application and logs tar -czf talk2me-backup.tar.gz \ /opt/talk2me \ /var/log/talk2me \ /etc/systemd/system/talk2me.service \ /etc/nginx/sites-available/talk2me ``` ## Troubleshooting ### Service Won't Start ```bash # Check service status systemctl status talk2me # Check logs journalctl -u talk2me -n 100 # Test configuration sudo -u talk2me /opt/talk2me/venv/bin/gunicorn --check-config wsgi:application ``` ### High Memory Usage ```bash # Trigger cleanup curl -X POST -H "X-Admin-Token: token" http://localhost:5005/admin/memory/cleanup # Restart workers systemctl reload talk2me ``` ### Slow Response Times 1. Check worker count 2. Enable async workers 3. Check GPU availability 4. Review nginx buffering settings ## Performance Optimization ### 1. Enable GPU Ensure CUDA/ROCm is properly installed: ```bash # Check GPU nvidia-smi # or rocm-smi # Set in environment export CUDA_VISIBLE_DEVICES=0 ``` ### 2. Optimize Workers ```python # For CPU-heavy workloads workers = cpu_count() threads = 1 # For I/O-heavy workloads workers = cpu_count() * 2 threads = 4 ``` ### 3. Enable Caching Use Redis for caching translations: ```python CACHE_TYPE = 'redis' CACHE_REDIS_URL = 'redis://localhost:6379/0' ``` ## Maintenance ### Regular Tasks 1. **Log Rotation**: Configured automatically 2. **Database Cleanup**: Run weekly 3. **Model Updates**: Check for Whisper updates 4. **Security Updates**: Keep dependencies updated ### Update Procedure ```bash # Backup first ./backup.sh # Update code git pull # Update dependencies sudo -u talk2me /opt/talk2me/venv/bin/pip install -r requirements-prod.txt # Restart service sudo systemctl restart talk2me ``` ## Rollback If deployment fails: ```bash # Stop service sudo systemctl stop talk2me # Restore backup tar -xzf talk2me-backup.tar.gz -C / # Restart service sudo systemctl start talk2me ```