---
title: Dify端到端性能测试
description: "Dify端到端性能测试包含三个测试：Dify知识库检索性能测试、Dify端到端问答吞吐测试和Dify端到端问答首token时延测试。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengrag/bestpractice/kunpengrag_21_0072.html
sourcePath: /source/zh/kunpengrag/bestpractice/kunpengrag_21_0072.html
indexId: f8708a6eb8d447bf65b66645458cdc0fc442ebd1a241df005785dd80427cbc0e58
---
# Dify端到端性能测试

Dify端到端性能测试包含三个测试：Dify知识库检索性能测试、Dify端到端问答吞吐测试和Dify端到端问答首token时延测试。

1. 进入“dify_test”目录。

```
cd KunpengRAG/test-utils/performance-test/dify-test
```


2. 根据用户需求和模型输入限制进行文档切分并导入数据准备阶段的语料数据到Dify知识库。
3. 在“KunpengRAG/test-utils/performance-test/common”目录下的common.py中配置用户自定义参数。

```
########### dify's variable ###########
# server host ip （dify服务IP）
SERVER_IP = ""
########### models variable ###########
# embedding模型IP和端口
EMBED_IP = ""
EMBED_PORT = ""
# Rerank模型IP和端口
RERANK_IP = ""
RERANK_PORT = ""
# LLM模型名字、IP和端口
LLM_NAME = ""
LLM_IP = ""
LLM_PORT = ""
# Rerank模型排序结果提取数量
TOP_K = 3
########### variable for dify api ###########
# dify知识库检索API KEY
KNOWLEDGE_API = 'dataset-xxxx'
# dataset id, dify知识库ID
DATASET_ID = 'xxxxx'
# dify chat api, dify聊天API KEY
CHAT_API = 'app-xxxxx'
# 知识库检索模式：keyword_search / semantic_search / full_text_search / hybrid_search
SEARCH_MODE = 'semantic_search'
# reranker enable or not（在问答过程中选择是否开启Rerank排序）
RERANK_ENABLE = True
# Rerank模型提供商使用llama.cpp启动Reranker服务openai_api_compatible，其他提供商根据用户需求选择，e.g. openai/deepseek/ollama/tongyi
MODELING_PROVIDER = 'openai_api_compatible'
# Reranker模型名字，用户在Dify Reranker模型配置时填写的名字
RERANK_MODEL_NAME = 'rerank'
```


  - 获取KNOWLEDGE_API：进入Dify前端页面，依此单击“知识库 > API > API密钥 > 创建密钥”。
  - 获取DATASET_ID：进入Dify前端页面，随后单击用户准备测试的知识库，此时界面URL上datasets后为知识库ID。
  - 获取CHAT_API：进入Dify前端页面，依此单击“工作室 > 创建空白应用（根据用户需求选择） > 进入应用 > 访问API > API密钥 > 创建密钥”。
4. （可选，用户可自行选择是否对问题进行固定长度裁切）选择需要提问的问题，填入test_text_length.py脚本中的“text”字段，脚本会对输入text进行245、256和512chunks进行裁切。脚本路径为“KunpengRAG/test-utils/performance-test/model_test/test_text_length.py”。
5. 进入“model_test”目录，运行test_text_length.py脚本。

```
python3 test_text_length.py
```


6. Dify知识库检索性能测试。

  a. 将用户问题填入“test_dify_knowledge_search.py”脚本中的TEXT_256_TOKENS、TEXT_512_TOKENS参数。脚本路径为“KunpengRAG/test-utils/performance-test/dify-test/test_dify_knowledge_search.py”。
  b. 使用Python执行“test_dify_knowledge_search.py”脚本，命令如下所示，其中2为并发请求数，用户可以根据需求进行选择。

```
python3 test_dify_knowledge_search.py 2
```


    返回结果包含打印输出和excel文档输出。

7. Dify端到端问答吞吐测试。

  a. 将用户问题填入“test_dify_llm_throught.py”脚本中的TEXT_256_TOKENS、TEXT_512_TOKENS参数。脚本路径为“KunpengRAG/test-utils/performance-test/dify-test/test_dify_llm_throught.py”。
  b. 使用Python执行“test_dify_llm_throught.py”脚本，命令如下所示，其中2为并发请求数，用户可以根据需求进行选择。

```
python3 test_dify_llm_throught.py 2
```


    返回结果包含打印输出和excel文档输出。

8. Dify端到端问答首token时延测试。

  a. 将用户问题填入“test_dify_llm.py”脚本中的TEXT_256_TOKENS、TEXT_512_TOKENS参数。脚本路径为“KunpengRAG/test-utils/performance-test/dify-test/test_dify_llm.py”。
  b. 使用Python执行“test_dify_llm.py”脚本，命令如下所示，其中2为并发请求数，用户可以根据需求进行选择。

```
python3 test_dify_llm.py 2
```


    返回结果包含打印输出和excel文档输出。
