python main.py)| 项 | 值 |
|---|---|
| 进程 PID | 96162 |
| 启动命令 | python main.py |
| 工作目录 | /Users/chaizi/Work/Projects/yusys/ai-study/code/four-level-schedule/parse-service |
| Web 框架 | FastAPI + Uvicorn |
| 监听地址 | 0.0.0.0:8000 |
| Worker 数 | 1 |
优先级:高
修改位置:parse-service/main.py:346
# 当前
uvicorn.run(
"main:app",
host="0.0.0.0",
port=8000,
workers=1 # ← 改这里
)
# 优化后
uvicorn.run(
"main:app",
host="0.0.0.0",
port=8000,
workers=4 # ← 改成 4 或更多(根据 CPU 核数)
)
注意:
优先级:高
需要创建:
parse-service/Dockerfileparse-service/requirements.txtDockerfile 示例:
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "main.py"]
优先级:中
方案架构:
Flink → Nginx (8000) → parse-service-1 (8001)
→ parse-service-2 (8002)
→ parse-service-3 (8003)
需要创建/修改:
docker-compose-parse-service.ymlparse-service/nginx.conf (Nginx 配置)docker-compose 示例:
services:
parse-service-1:
build: ./parse-service
ports:
- "8001:8000"
volumes:
- ./duomotai/examples:/data/examples
parse-service-2:
build: ./parse-service
ports:
- "8002:8000"
volumes:
- ./duomotai/examples:/data/examples
nginx:
image: nginx:alpine
ports:
- "8000:80"
volumes:
- ./parse-service/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- parse-service-1
- parse-service-2
nginx.conf 示例:
upstream parse_service {
server parse-service-1:8000;
server parse-service-2:8000;
}
server {
listen 80;
location / {
proxy_pass http://parse_service;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
优先级:低
/health 端点| Flink 并发 | parse-service 实例数 | 预期结果 |
|---|---|---|
| 1 | 1 | 基准性能 |
| 2 | 1 | 性能不提升(parse-service 瓶颈) |
| 2 | 2 | 性能≈2x |
| 4 | 2 | 性能≈2x(parse-service 瓶颈) |
| 4 | 4 | 性能≈4x |
parse-service/main.py(修改 workers)parse-service/requirements.txt(需要确认)schedule-manager/(实例管理)