Skip to main content

Display Helm Chart Values

helm show values dify/dify

1. Improve Resource Allocation

  • You can improve the performance of Dify by adjusting the resource allocation for services in the Helm chart values file.
  • You can increase these values based on your environment and available resources.
  • Recommended configuration for each component:
CategoryComponentReplicasRequest CPURequest MemLimit CPULimit MemNotes
Core ApplicationAPI611 GB12 GB
Worker244 GB48 GB
Worker Beat112 GB24 GB
Web10.51 GB12 GB
Sandbox122 GB24 GB
EnterpriseEnterprise122 GB22 GB
Enterprise_Audit112 GB24 GB
Enterprise_Frontend112 GB12 GB
PluginPlugin Daemon112 GB24 GB
Plugin Controller10.51 GB12 GB
Plugin Connector112 GB12 GB
Plugin Manager112 GB24 GB
InfrastructureSSRF Proxy10.50.5 GB11 GB
Gateway112 GB24 GB
Unstructured-----As needed
MinIO-----As needed
Notes:
  • API: Scale replicas horizontally as needed
  • Worker: Scale replicas horizontally as needed (if there are many files to upload)
  • Sandbox: Scale replicas horizontally as needed (if there are many compute tasks)
    • maxWorkers: 4 (number of worker processes)
    • workerTimeout: 15 (call timeout)
Configuration Example:
api:
  replicas: 6
  resources:
    requests:
      cpu: 1
      memory: 1Gi
    limits:
      cpu: 1
      memory: 2Gi

worker:
  replicas: 2
  resources:
    requests:
      cpu: 4
      memory: 4Gi
    limits:
      cpu: 4
      memory: 8Gi

sandbox:
  replicas: 1
  maxWorkers: 4
  workerTimeout: 15
  resources:
    requests:
      cpu: 2
      memory: 2Gi
    limits:
      cpu: 2
      memory: 4Gi

2. Improve External PostgreSQL Performance

2.1 Calculate Database Maximum Connections

When configuring the database, you need to calculate the required maximum connections using the following formula:
Max Connections = (SQLALCHEMY_POOL_SIZE + SQLALCHEMY_MAX_OVERFLOW) × API Workers × API Replicas
                + (SQLALCHEMY_POOL_SIZE + SQLALCHEMY_MAX_OVERFLOW) × Worker Workers × Worker Replicas
Parameters:
  • SQLALCHEMY_POOL_SIZE: Database connection pool size per worker
  • SQLALCHEMY_MAX_OVERFLOW: Maximum additional connections when pool overflows
  • API Workers: API service’s serverWorkerAmount
  • Worker Workers: Worker service’s celeryWorkerAmount
Calculation Example: Assuming the following configuration:
  • API: replicas=6, serverWorkerAmount=1
  • Worker: replicas=2, celeryWorkerAmount=1
  • SQLALCHEMY_POOL_SIZE=100
  • SQLALCHEMY_MAX_OVERFLOW=150
The maximum connections would be:
(100 + 150) × 1 × 6 + (100 + 150) × 1 × 2 = 1500 + 500 = 2000
It is recommended to reserve 20-30% headroom based on the calculation result to handle traffic spikes. In the above example, set max_connections to 2400-2600.

2.2 Complete Configuration Example

api:
  replicas: 6
  serverWorkerAmount: 1
  extraEnv:
    - name: SQLALCHEMY_POOL_SIZE
      value: "100"
    - name: SQLALCHEMY_MAX_OVERFLOW
      value: "150"
  resources:
    requests:
      cpu: 1
      memory: 1Gi
    limits:
      cpu: 1
      memory: 2Gi

3. Performance Monitoring Recommendations

3.1 Key Metrics

Monitor the following metrics to ensure the system is running well: Database Connections:
  • Current active connections
  • Connection pool utilization
  • Requests waiting for connections
Resource Usage:
  • CPU utilization (recommended to keep below 70%)
  • Memory utilization (recommended to keep below 80%)
  • Disk I/O
Application Performance:
  • API response time
  • Worker task queue length
  • Task execution time

3.2 Common Performance Bottlenecks

SymptomPossible CauseSolution
Slow API responseInsufficient API replicasIncrease API replicas
Task backlogInsufficient Worker capacityIncrease Worker replicas or celeryWorkerAmount
Database connection exhaustionInsufficient connectionsIncrease max_connections or optimize connection pool
Out of memoryMemory limit too lowIncrease memory limits
CPU throttlingCPU limit too lowIncrease CPU limits