Dify performance optimization (public preview)

Updated at:

Properly configure the specifications and number of Dify components and external resources to meet production performance requirements and improve resource utilization.

Important

Responsibility boundary: Applications deployed from the Application Center, unless otherwise specified, are consistent with their open-source community versions. You are responsible for any stability risks and security vulnerabilities associated with the open-source software. SAE's service assurance is limited to the stability of the underlying runtime and does not cover the quality, security, or maintenance of the open-source software itself. Conduct a thorough technical review and security audit before deploying to a production environment.

Procedure

  1. Deploy Dify on SAE (public preview). If you require performance of 500 QPS or higher, select Dify High-Performance Edition during deployment.

  2. Adjust the configuration of Dify components and external resources based on the minimum resource sets for each performance tier:

    1. Adjust the instance specification and number of instances for each Dify component.

    2. To adjust the Redis instance specification, log on to the Redis console. In the left-side navigation pane, click Instance List and select the region at the top of the page. Find the target Redis instance and click Change Configuration in the Actions column. Alternatively, click Manage in the Actions column, then navigate to Instance Information in the left-side navigation pane to adjust the configuration.

    3. To adjust the PostgreSQL instance specification, log on to the RDS console. In the left-side navigation pane, click Instance List and select the region at the top of the page. In the Actions column of the target PostgreSQL instance, click Manage. On the instance details page, navigate to Basic Information in the left-side navigation pane to adjust the configuration.

    4. To adjust the NAT Gateway instance specification, log on to the NAT Gateway console. Select the region at the top of the page. In the Actions column of the target NAT Gateway instance, click Manage. On the Associated EIPs tab, click the Instance ID of the target elastic IP address. On the details page that appears, choose More > Upgrade/Downgrade from the upper-right corner.

Minimum resource sets for each performance tier

Tier 1: 10 QPS

Dify components

Component name

Instance specification

Number of instances

dify-nginx

1-core CPU, 2 GB memory

1

dify-api

1-core CPU, 2 GB memory

1

dify-plugin-daemon

1-core CPU, 2 GB memory

1

dify-worker

1-core CPU, 2 GB memory

1

dify-sandbox

1-core CPU, 2 GB memory

1

dify-web

1-core CPU, 2 GB memory

1

External resources

Resource type

Instance specification

Redis

  • Architecture type: Non-cluster

  • Product type: Community Edition

  • Version: 6.0

  • Specification: 2 GB (redis.shard.mid.2.ce)

  • Bandwidth: 96 MB/s

  • Read/write splitting: Disabled (1 primary, 1 replica)

  • Maximum connections: 10,000

  • Number of shards: 1

PostgreSQL

  • CPU: 2-core

  • Database Memory: 8 GB

  • Instance specification: pg.n4.2c.2m

  • Default connections: 800

NAT Gateway

  • Type: Enhanced

  • Peak bandwidth of EIP: 5 Mbps

Tier 2: 100 QPS

Dify components

Component name

Instance specification

Number of instances

dify-nginx

1-core CPU, 2 GB memory

1

dify-api

8-core CPU, 8 GB memory

2

dify-plugin-daemon

2-core CPU, 4 GB memory

4

dify-worker

1-core CPU, 2 GB memory

1

dify-sandbox

1-core CPU, 2 GB memory

1

dify-web

1-core CPU, 2 GB memory

1

External resources

Resource type

Instance specification

Redis

  • Architecture type: Non-cluster

  • Product type: Community Edition

  • Version: 6.0

  • Specification: 2 GB (redis.shard.mid.2.ce)

  • Bandwidth: 96 MB/s

  • Read/write splitting: Disabled (1 primary, 1 replica)

  • Maximum connections: 10,000

  • Number of shards: 1

PostgreSQL

  • CPU: 2-core

  • Database Memory: 8 GB

  • Instance specification: pg.n4.2c.2m / pg.n4.4c.2m

  • Default connections: 800

NAT Gateway

  • Type: Enhanced

  • Peak bandwidth of EIP: 100 Mbps

Tier 3: 200 QPS

Dify components

Component name

Instance specification

Number of instances

dify-nginx

1-core CPU, 2 GB memory

2

dify-api

12-core CPU, 12 GB memory

5

dify-plugin-daemon

2-core CPU, 4 GB memory

10

dify-worker

1-core CPU, 2 GB memory

1

dify-sandbox

1-core CPU, 2 GB memory

1

dify-web

1-core CPU, 2 GB memory

1

External resources

Resource type

Instance specification

Redis

  • Option 1: Non-cluster configuration

    • Architecture type: Non-cluster

    • Product type: Community Edition

    • Version: 6.0

    • Specification: 16 GB (redis.shard.2xlarge.ce)

    • Bandwidth: 288 MB/s

    • Read/write splitting: Disabled (1 primary, 1 replica)

    • Maximum connections: 20,000

    • Number of shards: 1

  • Option 2: Cluster configuration

    • Architecture type: Cluster

    • Product type: Community Edition

    • Version: 6.0

    • Specification: 1 GB (redis.shard.small.ce)

    • Bandwidth: 288 MB/s

    • Read/write splitting: Disabled (1 primary, 1 replica)

    • Maximum connections: 30,000

    • Number of shards: 3

PostgreSQL

  • CPU: 16-core

  • Database Memory: 128 GB

  • Instance specification: pg.x8.2xlarge.2c

  • Default connections: 12,800

NAT Gateway

  • Type: Enhanced

  • Peak bandwidth of EIP: 100 Mbps

Tier 4: 500 QPS (for Dify High-Performance Edition)

Dify components

Component name

Instance specification

Number of instances

dify-nginx

1-core CPU, 2 GB memory

2

dify-api

12-core CPU, 12 GB memory

8

dify-plugin-daemon

2-core CPU, 4 GB memory

16

dify-worker

1-core CPU, 2 GB memory

1

dify-sandbox

1-core CPU, 2 GB memory

1

dify-web

1-core CPU, 2 GB memory

1

External resources

Resource type

Instance specification

Redis

  • Option 1: Non-cluster configuration

    • Architecture type: Non-cluster

    • Product type: Community Edition

    • Version: 6.0

    • Specification: 16 GB (redis.shard.2xlarge.ce)

    • Bandwidth: 288 MB/s

    • Read/write splitting: Disabled (1 primary, 1 replica)

    • Maximum connections: 20,000

    • Number of shards: 1

  • Option 2: Cluster configuration

    • Architecture type: Cluster

    • Product type: Community Edition

    • Version: 6.0

    • Specification: 1 GB (redis.shard.small.ce)

    • Bandwidth: 288 MB/s

    • Read/write splitting: Disabled (1 primary, 1 replica)

    • Maximum connections: 30,000

    • Number of shards: 3

PostgreSQL

  • CPU: 64-core

  • Database Memory: 256 GB

  • Instance specification: pg.x4.8xlarge.2c

  • Default connections: 25,600

NAT Gateway

  • Type: Enhanced

  • Peak bandwidth of EIP: 100 Mbps