Dify部署
dify可以分成两部分部署,核心服务+中间件
- difyapi服务器,使用.env和docker-compose.yaml
dify web
dify api
dify worker
dify workerbeat 定时器服务
启动命令
sudo docker compose down && sudo docker compose up -d
- Dify 依赖的中间件服务器,使用middleware.env和docker-compose.middleware.yaml
数据库
postgres:15-alpine
redis:6-alpine
emitechnologies/weaviate:1.27.0
langgenius/dify-sandbox:0.2.12 用于python代码执行
langgenius/dify-plugin-daemon:0.5.1-local 插件相关
启动命令
sudo docker compose -f docker-compose.middleware.yaml --profile postgresql --profile weaviate -p dify down && sudo docker compose -f docker-compose.middleware.yaml --profile postgresql --profile weaviate -p dify up -d
difyapi服务配置
- node节点的并发数量控制
# Minimum number of workers per GraphEngine instance (default: 1)
GRAPH_ENGINE_MIN_WORKERS=5
# Maximum number of workers per GraphEngine instance (default: 10)
GRAPH_ENGINE_MAX_WORKERS=10
- dify连接数配置
SERVER_WORKER_CONNECTIONS=1000
Sandbox服务配置
- 源码:https://github.com/langgenius/dify-sandbox
- 环境变量设置以下两个用于并发的参数
MAX_REQUESTS: ${SANDBOX_MAX_REQUESTS:-1000}
MAX_WORKERS: ${SANDBOX_MAX_WORKERS:-100}
- 超时时间
CODE_EXECUTION_READ_TIMEOUT=120
CODE_EXECUTION_WRITE_TIMEOUT=20
plugin-daemon服务配置
- 并发的配置项在compose文件和env文件中并没有出现,但是从plugin-daemon源码中可以发现
- 源码地址:https://github.com/langgenius/dify-plugin-daemon
PLUGIN_LOCAL_LAUNCHING_CONCURRENT = 200 // 并发选项
PLUGIN_MAX_EXECUTION_TIMEOUT = 600 // 执行超时时间
Postgresql 配置
- 由于dify没有做连接池管理,在实际使用中会出现数据库连接耗尽的情况,所以使用一个第三方链接池管理工具pgbouncer,difyapi直接连接pgbouncer
- postgressql最大连接数配置
POSTGRES_MAX_CONNECTIONS = 1000 // 最大连接数
参考资料
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Moyin!