PERF 提升容器并发数量

ADD 增加dockerfile与对应的docker-compose文件
This commit is contained in:
2025-03-18 15:19:00 +08:00
parent e2135dd915
commit 7553ef0a2e
5 changed files with 174 additions and 7 deletions

2
.idea/misc.xml generated
View File

@@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.9 (pythonProject)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (modalDeploy)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="ComfyUI" project-jdk-type="Python SDK" />
</project>

2
.idea/modalDeploy.iml generated
View File

@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (modalDeploy)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="ComfyUI" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

22
docker-compose.yaml Normal file
View File

@@ -0,0 +1,22 @@
services:
comfyui-service:
image: comfyui-image:v1.2
container_name: comfyui
ports:
- 8188:8188
ipc: host
deploy:
resources:
limits:
memory: 64000M
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [ gpu ]
volumes:
#- ./custom_nodes:/app/ComfyUI/custom_nodes
- E://models:/root/comfy/ComfyUI/models
- E://comfy//ComfyUI//input:/root/comfy/ComfyUI/input
# - s3:/app/ComfyUI/input_s3
#- s3:/app/ComfyUI/output_s3

134
dockerfile Normal file
View File

@@ -0,0 +1,134 @@
# 使用 Debian Slim 作为基础镜像
FROM python:3.10-slim
# 创建并配置腾讯云的 apt 源
RUN apt update
RUN apt install -y wget
RUN wget https://linuxmirrors.cn/main.sh
RUN bash main.sh --source mirrors.cloud.tencent.com
RUN apt update
# 替换 pip 源为阿里云
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 安装 git
RUN apt-get update && apt-get install -y git
# 安装 Python 依赖
RUN pip install fastapi[standard]==0.115.4 \
comfy-cli==1.3.5 \
cos-python-sdk-v5 \
sqlalchemy \
ultralytics \
tencentcloud-sdk-python \
pymysql \
Pillow \
ffmpy \
opencv-python \
av \
imageio \
loguru
# 安装 ComfyUI 及其依赖
RUN comfy --skip-prompt install --nvidia --version 0.3.10
# 克隆并安装自定义节点
RUN git clone https://github.com/M1kep/ComfyLiterals /root/comfy/ComfyUI/custom_nodes/ComfyLiterals && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyLiterals/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyLiterals/requirements.txt; fi
RUN git clone https://github.com/evanspearman/ComfyMath /root/comfy/ComfyUI/custom_nodes/ComfyMath && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyMath/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyMath/requirements.txt; fi
RUN git clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved /root/comfy/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/requirements.txt; fi
RUN git clone https://e.coding.net/g-ldyi2063/dev/ComfyUI-Bowong.git /root/comfy/ComfyUI/custom_nodes/ComfyUI-Bowong && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-Bowong/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-Bowong/requirements.txt; fi
RUN git clone https://github.com/crystian/ComfyUI-Crystools /root/comfy/ComfyUI/custom_nodes/ComfyUI-Crystools && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-Crystools/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-Crystools/requirements.txt; fi
RUN git clone https://github.com/pythongosssss/ComfyUI-Custom-Scripts /root/comfy/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts/requirements.txt; fi
RUN git clone https://github.com/BennyKok/comfyui-deploy /root/comfy/ComfyUI/custom_nodes/comfyui-deploy && \
if [ -f /root/comfy/ComfyUI/custom_nodes/comfyui-deploy/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/comfyui-deploy/requirements.txt; fi
RUN git clone https://github.com/yolain/ComfyUI-Easy-Use /root/comfy/ComfyUI/custom_nodes/ComfyUI-Easy-Use && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-Easy-Use/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-Easy-Use/requirements.txt; fi
RUN git clone https://e.coding.net/g-ldyi2063/dev/ComfyUI-VideoHelperSuite.git /root/comfy/ComfyUI/custom_nodes/ComfyUI-VideoHelperSuite && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-VideoHelperSuite/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-VideoHelperSuite/requirements.txt; fi
#防止依赖安装问题
RUN pip install conformer==0.3.2 einops>0.6.1 --no-dependencies
RUN pip install -U openai-whisper
RUN apt install --reinstall -y gcc
RUN git clone https://e.coding.net/g-ldyi2063/dev/CosyVoice-ComfyUI.git /root/comfy/ComfyUI/custom_nodes/CosyVoice-ComfyUI && \
if [ -f /root/comfy/ComfyUI/custom_nodes/CosyVoice-ComfyUI/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/CosyVoice-ComfyUI/requirements.txt; fi
RUN git clone https://github.com/jags111/efficiency-nodes-comfyui /root/comfy/ComfyUI/custom_nodes/efficiency-nodes-comfyui && \
if [ -f /root/comfy/ComfyUI/custom_nodes/efficiency-nodes-comfyui/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/efficiency-nodes-comfyui/requirements.txt; fi
RUN git clone https://github.com/WASasquatch/was-node-suite-comfyui /root/comfy/ComfyUI/custom_nodes/was-node-suite-comfyui && \
if [ -f /root/comfy/ComfyUI/custom_nodes/was-node-suite-comfyui/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/was-node-suite-comfyui/requirements.txt; fi
RUN git clone https://github.com/rgthree/rgthree-comfy /root/comfy/ComfyUI/custom_nodes/rgthree-comfy && \
if [ -f /root/comfy/ComfyUI/custom_nodes/rgthree-comfy/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/rgthree-comfy/requirements.txt; fi
RUN git clone https://github.com/cubiq/ComfyUI_essentials /root/comfy/ComfyUI/custom_nodes/ComfyUI_essentials && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI_essentials/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI_essentials/requirements.txt; fi
RUN git clone https://github.com/melMass/comfy_mtb /root/comfy/ComfyUI/custom_nodes/comfy_mtb && \
if [ -f /root/comfy/ComfyUI/custom_nodes/comfy_mtb/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/comfy_mtb/requirements.txt; fi
RUN git clone https://e.coding.net/g-ldyi2063/dev/ComfyUI-CustomNode.git /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/requirements.txt; fi
RUN git clone https://e.coding.net/g-ldyi2063/dev/ComfyUI-LatentSync-Node.git /root/comfy/ComfyUI/custom_nodes/ComfyUI-LatentSync-Node && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI-LatentSync-Node/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI-LatentSync-Node/requirements.txt; fi
#解决PortAudio library not found问题
RUN apt-get install -y libportaudio2
RUN git clone https://e.coding.net/g-ldyi2063/dev/ComfyUI_SparkTTS.git /root/comfy/ComfyUI/custom_nodes/ComfyUI_SparkTTS && \
if [ -f /root/comfy/ComfyUI/custom_nodes/ComfyUI_SparkTTS/requirements.txt ]; then pip install -r /root/comfy/ComfyUI/custom_nodes/ComfyUI_SparkTTS/requirements.txt; fi
# 创建符号链接
RUN mkdir -p /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model && \
rm -rf /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model && \
ln -s /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model
RUN mkdir -p /root/comfy/ComfyUI/models/ComfyUI-LatentSync-Node/checkpoints && \
rm -rf /root/comfy/ComfyUI/custom_nodes/ComfyUI-LatentSync-Node/checkpoints && \
ln -s /root/comfy/ComfyUI/models/ComfyUI-LatentSync-Node/checkpoints /root/comfy/ComfyUI/custom_nodes/ComfyUI-LatentSync-Node/checkpoints
RUN mkdir -p /root/comfy/ComfyUI/models/CosyVoice-ComfyUI/pretrained_models/CosyVoice-300M && \
mkdir -p /root/comfy/ComfyUI/custom_nodes/CosyVoice-ComfyUI/pretrained_models/CosyVoice-300M && \
rm -rf /root/comfy/ComfyUI/custom_nodes/CosyVoice-ComfyUI/pretrained_models/CosyVoice-300M && \
ln -s /root/comfy/ComfyUI/models/CosyVoice-ComfyUI/pretrained_models/CosyVoice-300M /root/comfy/ComfyUI/custom_nodes/CosyVoice-ComfyUI/pretrained_models/CosyVoice-300M
RUN mkdir -p /root/comfy/ComfyUI/models/.cache/torch/hub/checkpoints && \
mkdir -p /root/.cache/torch/hub/checkpoints && \
rm -rf /root/.cache/torch/hub/checkpoints && \
ln -s /root/comfy/ComfyUI/models/.cache/torch/hub/checkpoints /root/.cache/torch/hub/checkpoints
RUN mkdir -p /root/comfy/ComfyUI/models/stabilityai && \
ln -s /root/comfy/ComfyUI/models/stabilityai /root/comfy/ComfyUI/stabilityai
RUN rm -rf /root/comfy/ComfyUI/models
# 安装 ffmpeg
RUN apt-get update && apt-get install -y ffmpeg && ffmpeg -version
# 添加本地配置文件
COPY config.yaml /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml
WORKDIR /root/comfy
CMD ["comfy", "--here", "launch", "--", "--listen", "0.0.0.0", "--port", "8188"]

View File

@@ -2,6 +2,7 @@ import json
import os
import shutil
import subprocess
import sys
import uuid
from pathlib import Path
from typing import Dict
@@ -13,6 +14,8 @@ image = ( # build up a Modal Image to run ComfyUI, step by step
python_version="3.10"
)
.apt_install("git") # install git to clone ComfyUI
.apt_install("gcc")
.apt_install("libportaudio2")
.pip_install("fastapi[standard]==0.115.4") # install web dependencies
.pip_install("comfy-cli==1.3.5") # install comfy-cli
.pip_install("cos-python-sdk-v5")
@@ -26,6 +29,9 @@ image = ( # build up a Modal Image to run ComfyUI, step by step
.pip_install("av")
.pip_install("imageio")
.pip_install("loguru")
.pip_install("conformer==0.3.2",extra_options="--no-dependencies")
.pip_install("einops>0.6.1",extra_options="--no-dependencies")
.pip_install("openai-whisper")
.run_commands( # use comfy-cli to install ComfyUI and its dependencies
"comfy --skip-prompt install --nvidia --version 0.3.10"
)
@@ -38,7 +44,6 @@ image = (
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-Bowong.git")
.run_commands("comfy node install https://github.com/crystian/ComfyUI-Crystools")
.run_commands("comfy node install https://github.com/pythongosssss/ComfyUI-Custom-Scripts")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-CustomNode.git")
.run_commands("comfy node install https://github.com/BennyKok/comfyui-deploy")
.run_commands("comfy node install https://github.com/yolain/ComfyUI-Easy-Use")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-VideoHelperSuite.git")
@@ -48,8 +53,9 @@ image = (
.run_commands("comfy node install https://github.com/rgthree/rgthree-comfy")
.run_commands("comfy node install https://github.com/cubiq/ComfyUI_essentials")
.run_commands("comfy node install https://github.com/melMass/comfy_mtb")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-FFmpeg.git")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-CustomNode.git")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-LatentSync-Node.git")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI_SparkTTS.git")
.run_commands(
"mkdir -p /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model && rm -rf /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model && ln -s /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model"
).run_commands(
@@ -80,8 +86,8 @@ output_dir = "/root/comfy/ComfyUI/output"
@app.cls(
allow_concurrent_inputs=1, # allow 10 concurrent API calls
concurrency_limit=50,
container_idle_timeout=120,
max_containers=200,
scaledown_window=120,
# 5 minute container keep alive after it processes an input; increasing this value is a great way to reduce ComfyUI cold start times
timeout=900,
gpu="L4",
@@ -117,7 +123,6 @@ class ComfyUI:
# runs the comfy run --workflow command as a subprocess
session_id = str(uuid.uuid4())
workflow = json.loads(workflow_json)
file_to_move = None
for node in workflow.values():
if node.get("class_type") == "ComfyUIDeployExternalText":
if node.get("inputs").get("input_id") == "file_path":
@@ -163,3 +168,9 @@ class ComfyUI:
print("json", j)
return Response(content=json.dumps(j), media_type="application/json")
# @modal.web_endpoint(method="POST", label="tk")
# def tk_api(self, item: Dict):
# pass
#