Skip to content

Commit 4ed49d2

Browse files
authored
Replace gunicorn deployment to granian (#705)
* Replace gunicorn deployment to granian * Update env comments * Fix the granian env
1 parent 7b5ae46 commit 4ed49d2

File tree

6 files changed

+119
-66
lines changed

6 files changed

+119
-66
lines changed

Dockerfile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,39 @@ COPY --from=builder /usr/local /usr/local
3838

3939
COPY deploy/backend/supervisord.conf /etc/supervisor/supervisord.conf
4040

41+
WORKDIR /fba/backend
42+
4143
# === FastAPI server image ===
4244
FROM base_server AS fastapi_server
4345

44-
WORKDIR /fba
45-
4646
COPY deploy/backend/fastapi_server.conf /etc/supervisor/conf.d/
4747

4848
RUN mkdir -p /var/log/fastapi_server
4949

5050
EXPOSE 8001
5151

52-
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port","8000"]
52+
# Granian env
53+
ENV GRANIAN_HOST=0.0.0.0 \
54+
GRANIAN_PORT=8001 \
55+
# 并行工作进程数
56+
GRANIAN_WORKERS=1 \
57+
# 监听队列
58+
GRANIAN_BACKLOG=1024 \
59+
# 每个工作进程处理超时时间
60+
GRANIAN_WORKERS_KILL_TIMEOUT=120 \
61+
# 每个工作进程最大并发量
62+
GRANIAN_BACKPRESSURE=2000 \
63+
# PID 文件
64+
GRANIAN_PID_FILE='/var/run/granian.pid' \
65+
# 日志
66+
GRANIAN_LOG_ENABLED=true \
67+
GRANIAN_LOG_LEVEL='debug'
68+
69+
CMD ["/usr/local/bin/granian", "main:app", "--interface", "asgi", "--host", "0.0.0.0", "--port","8000"]
5370

5471
# === Celery server image ===
5572
FROM base_server AS celery
5673

57-
WORKDIR /fba/backend
58-
5974
COPY deploy/backend/celery.conf /etc/supervisor/conf.d/
6075

6176
RUN mkdir -p /var/log/celery

deploy/backend/fastapi_server.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[program:fastapi_server]
2-
directory=/fba
3-
command=/usr/local/bin/gunicorn -c /fba/deploy/backend/gunicorn.conf.py main:app
2+
directory=/fba/backend
3+
command=/usr/local/bin/granian main:app --interface asgi
44
user=root
55
autostart=true
66
autorestart=true

deploy/backend/gunicorn.conf.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
volumes:
1414
- ./deploy/backend/docker-compose/.env.server:/fba/backend/.env
1515
- fba_static:/fba/backend/app/static
16+
- fba_static_upload:/fba/backend/static/upload
1617
networks:
1718
- fba_network
1819
command:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ lint = [
6060
"pre-commit>=4.0.0",
6161
]
6262
server = [
63-
"gunicorn>=21.2.0",
6463
"aio-pika>=9.4.3",
64+
"granian>=2.4.0",
6565
"wait-for-it>=2.2.2",
6666
]
6767

0 commit comments

Comments
 (0)