docs: add multi-image image generation task
This commit is contained in:
+17
-3
@@ -13,6 +13,7 @@
|
||||
/media/ -> MEDIA_ROOT(MVP 本地媒体;后续可换对象存储)
|
||||
/api/v1/generate/image/tasks* -> Gunicorn 普通请求池(异步提交/轮询,短请求)
|
||||
/api/v1/generate/* -> Gunicorn 长请求池(旧同步生成,超时更长)
|
||||
/api/v1/analyze/images -> Gunicorn 长请求池(同步多图理解)
|
||||
其他路径 -> Gunicorn 普通请求池(用户端 / admin / 余额 / 充值)
|
||||
-> cmhub Django 单体
|
||||
-> cmhub image-task worker(management command,后台处理异步生图)
|
||||
@@ -24,6 +25,7 @@
|
||||
|
||||
- 使用系统 Python 3.12,不使用虚拟环境。
|
||||
- 图片生成已提供旧同步接口和新异步提交 / 轮询接口;真实图片生成耗时仍需在生产链路记录,并用于校准旧同步超时和异步 worker 容量。
|
||||
- T-619 多图理解为同步接口,必须分流到长请求池;请求体上限需覆盖 Base64 膨胀,默认 32 MiB 解码后总图片上限建议配置至少 50 MiB 的 Nginx `client_max_body_size`。
|
||||
- 真实支付需微信 / 支付宝商户密钥、证书、生产 SDK 与公网回调地址;未配置前只能用 `PAYMENT_CALLBACK_MODE=mock`。
|
||||
|
||||
## 二、系统准备
|
||||
@@ -241,7 +243,7 @@ python3.12 manage.py smoke_ai_generation title
|
||||
|
||||
## 七、Gunicorn 运行
|
||||
|
||||
建议把同步图片生成分流到独立 Gunicorn 池,避免长请求占满普通页面和 admin 的 worker。
|
||||
建议把同步图片生成与同步多图理解分流到独立 Gunicorn 池,避免长请求占满普通页面和 admin 的 worker。
|
||||
|
||||
普通请求池示例:
|
||||
|
||||
@@ -269,7 +271,7 @@ gunicorn config.wsgi:application \
|
||||
--error-logfile -
|
||||
```
|
||||
|
||||
`--timeout` 必须按真实图片生成耗时校准:生图 Provider 实际读取超时为 `min(AiModel.timeout_seconds 或分辨率默认值, AI_IMAGE_UPSTREAM_DEADLINE_SECONDS)`;`Gunicorn timeout` 应大于这个内层上游硬截止,Nginx `proxy_read_timeout` 应大于 Gunicorn timeout,调用方 read timeout 应不小于 Nginx。
|
||||
`--timeout` 必须按真实生成耗时校准:生图 Provider 实际读取超时为 `min(AiModel.timeout_seconds 或分辨率默认值, AI_IMAGE_UPSTREAM_DEADLINE_SECONDS)`;多图理解读取超时取视觉模型的文本请求超时。`Gunicorn timeout` 应大于内层上游超时,Nginx `proxy_read_timeout` 应大于 Gunicorn timeout,调用方 read timeout 应不小于 Nginx。
|
||||
|
||||
systemd 单元可分别命名为 `cmhub-web.service` 和 `cmhub-generate.service`。服务的 `WorkingDirectory` 指向 `/www/wwwroot/cmhub`,`ExecStart` 使用上面的两条 Gunicorn 命令,环境变量由项目根目录 `.env` 在 Django settings 中读取。
|
||||
|
||||
@@ -371,7 +373,7 @@ server {
|
||||
listen 443 ssl http2;
|
||||
server_name cmhub.example.com;
|
||||
|
||||
client_max_body_size 25m;
|
||||
client_max_body_size 64m;
|
||||
|
||||
location /static/ {
|
||||
alias /www/wwwroot/cmhub/staticfiles/;
|
||||
@@ -407,6 +409,17 @@ server {
|
||||
proxy_read_timeout 120s;
|
||||
}
|
||||
|
||||
location = /api/v1/analyze/images {
|
||||
proxy_pass http://127.0.0.1:8002;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_connect_timeout 30s;
|
||||
proxy_send_timeout 360s;
|
||||
proxy_read_timeout 360s;
|
||||
}
|
||||
|
||||
location /api/v1/generate/ {
|
||||
proxy_pass http://127.0.0.1:8002;
|
||||
proxy_set_header Host $host;
|
||||
@@ -436,6 +449,7 @@ server {
|
||||
- `/static/` 必须指向 `STATIC_ROOT`,否则 Bootstrap/qrcode 本地资源在 `DEBUG=False` 下 404。
|
||||
- `/media/` 是 MVP 本地图片结果访问路径;如果改对象存储,应同步更新 `MEDIA_URL` 和存储配置。
|
||||
- `/api/v1/generate/image/tasks` 与 `/api/v1/generate/image/tasks/{task_id}` 必须写在 `/api/v1/generate/` 前面,确保异步提交 / 轮询走普通 web 池;旧同步生成接口继续走长请求池。
|
||||
- `/api/v1/analyze/images` 不在 `/api/v1/generate/` 前缀下,必须单独写精确 location 并转发到长请求池;否则会落入普通 web 池并可能拖慢登录、余额和 admin。
|
||||
- 宝塔若已在外层配置 HTTP 到 HTTPS 跳转,`DJANGO_SECURE_SSL_REDIRECT=false` 即可;如果由 Django 负责跳转,再设为 `true`。
|
||||
|
||||
## 九、上线前验证
|
||||
|
||||
Reference in New Issue
Block a user