What a mess
This commit is contained in:
28
api/start.sh
Normal file
28
api/start.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# Startup script for API with auto-scaling workers
|
||||
|
||||
# Detect number of CPU cores
|
||||
CPU_CORES=$(nproc)
|
||||
|
||||
# Calculate optimal workers: (2 x CPU cores) + 1
|
||||
# But cap at 8 workers to avoid over-saturation
|
||||
WORKERS=$((2 * CPU_CORES + 1))
|
||||
if [ $WORKERS -gt 8 ]; then
|
||||
WORKERS=8
|
||||
fi
|
||||
|
||||
# Use environment variable if set, otherwise use calculated value
|
||||
WORKERS=${API_WORKERS:-$WORKERS}
|
||||
|
||||
echo "Starting API with $WORKERS workers (detected $CPU_CORES CPU cores)"
|
||||
|
||||
exec gunicorn api.main:app \
|
||||
--workers $WORKERS \
|
||||
--worker-class uvicorn.workers.UvicornWorker \
|
||||
--bind 0.0.0.0:8000 \
|
||||
--timeout 120 \
|
||||
--max-requests 1000 \
|
||||
--max-requests-jitter 100 \
|
||||
--access-logfile - \
|
||||
--error-logfile - \
|
||||
--log-level info
|
||||
Reference in New Issue
Block a user