Commit
This commit is contained in:
18
api/start.sh
18
api/start.sh
@@ -1,20 +1,14 @@
|
||||
#!/bin/bash
|
||||
# Startup script for API with auto-scaling workers
|
||||
|
||||
# Detect number of CPU cores
|
||||
# Auto-detect worker count based on CPU cores
|
||||
# Formula: (CPU_cores / 2) + 1, min 2, max 8
|
||||
CPU_CORES=$(nproc)
|
||||
WORKERS=$(( ($CPU_CORES / 2) + 1 ))
|
||||
WORKERS=$(( WORKERS < 2 ? 2 : WORKERS ))
|
||||
WORKERS=$(( WORKERS > 8 ? 8 : WORKERS ))
|
||||
|
||||
# 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)"
|
||||
echo "Starting API with $WORKERS workers (auto-detected from $CPU_CORES CPU cores)"
|
||||
|
||||
exec gunicorn api.main:app \
|
||||
--workers $WORKERS \
|
||||
|
||||
Reference in New Issue
Block a user