并发性能性化
更新时间:2025年3月14日 22:31
浏览:327
docker-compose.yaml 优化
api 启用 10 个实例
api:
image: langgenius/dify-api:0.15.3
restart: always
deploy:
replicas: 10
后台 worker 启用 3 个实例
worker:
image: langgenius/dify-api:0.15.3
restart: always
deploy:
replicas: 3
.env 参数优化
数据库连接池大小
# The size of the database connection pool.
# The default is 30 connections, which can be appropriately increased.
#SQLALCHEMY_POOL_SIZE=30
SQLALCHEMY_POOL_SIZE=300
PG 数据库最大连接数
需要保证 (api 实例数 + worker 实例数) * 连接池大小 < PG 数据库最大连接数
# Maximum number of connections to the database
# Default is 100
#
# Reference: https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-MAX-CONNECTIONS
#POSTGRES_MAX_CONNECTIONS=100
POSTGRES_MAX_CONNECTIONS=4000
PG 使用共享内存作为共享缓存的大小
# Sets the amount of shared memory used for postgres's shared buffers.
# Default is 128MB
# Recommended value: 25% of available memory
# Reference: https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-SHARED-BUFFERS
# POSTGRES_SHARED_BUFFERS=128MB
POSTGRES_SHARED_BUFFERS=1280MB
PG 缓存
# Sets the planner's assumption about the effective cache size.
# Default is 4096MB
#
# Reference: https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-EFFECTIVE-CACHE-SIZE
# POSTGRES_EFFECTIVE_CACHE_SIZE=4096MB
POSTGRES_EFFECTIVE_CACHE_SIZE=20480MB