Closed rechardwang closed 1 month ago
Hey @rechardwang! 👋 I'm here to help you with any bugs, questions, or contributions you have for the project. Let's work together to solve this issue!
I found some similar issues and discussions that might help you troubleshoot the slow response times with the /v1/chat-messages
API endpoint:
invoke_llm
method to improve responsiveness. Here is the suggested code modification:
llm_result: LLMResult = model_instance.invoke_llm(
prompt_messages=prompt_messages,
model_parameters=app_orchestration_config.model_config.parameters,
tools=[],
stop=app_orchestration_config.model_config.stop,
stream=True, # Enable streaming
user=self.user_id,
callbacks=[],
)
For optimizing the performance of the /v1/chat-messages
API endpoint, consider the following server and network configurations for running Dify in a self-hosted Docker environment:
API Server Configuration:
0.0.0.0
.5001
.number of CPU cores x 2 + 1
.gevent
.200
. Recommended value is 360
to support longer SSE (Server-Sent Events) connection times.Database Configuration:
5432
), DB_DATABASE.30
connections.3600
seconds.Redis Configuration:
6379
), REDIS_DB (Default: 0
), REDIS_PASSWORD.false
.Celery Configuration:
gevent
.1
.File Storage Configuration:
local
.Network Configuration:
5001
for API, 5432
for PostgreSQL, 6379
for Redis).Example Docker Compose configuration snippet:
version: '3.8'
services:
api:
image: dify/api:latest
environment:
- DIFY_BIND_ADDRESS=0.0.0.0
- DIFY_PORT=5001
- SERVER_WORKER_AMOUNT=5 # Adjust based on CPU cores
- GUNICORN_TIMEOUT=360
- DB_HOST=your_db_host
- DB_PORT=5432
- REDIS_HOST=your_redis_host
- REDIS_PORT=6379
- REDIS_PASSWORD=your_redis_password
- STORAGE_TYPE=local
ports:
- "5001:5001"
volumes:
- ./storage:/app/api/storage
db:
image: postgres:latest
environment:
- POSTGRES_USER=your_db_user
- POSTGRES_PASSWORD=your_db_password
- POSTGRES_DB=your_db_name
ports:
- "5432:5432"
redis:
image: redis:latest
environment:
- REDIS_PASSWORD=your_redis_password
ports:
- "6379:6379"
This configuration ensures that the Dify API server, PostgreSQL database, and Redis instance are properly set up and can communicate with each other, providing a robust environment for optimal performance [4][5][6].
To continue talking to Dosu, mention @dosu.
所以 /v1/chat-messages 速度提不起来吗?
不行,LLM 那边应该生成很快,但是计算token会变慢,暂时应该没有时间修复。
@crazywoola 这个问题最终是修复了还是没有修复? 不修复压测都过不了。压测的时候加入dify chat-messages这个api封装是直通的2倍时间。
Self Checks
Dify version
0.8.2
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Given that the issue of slow response times with the /v1/chat-messages API endpoint began after upgrading to version 0.8.2, it's likely that the upgrade introduced changes affecting performance
When using the console page for debugging, the speed is very fast.
It seems that when you use the /v1/chat-messages API endpoint, the response is slow, and this slowness is also reflected in the console logs. This indicates that the issue is likely not related to network.
✔️ Expected Behavior
No response
❌ Actual Behavior
No response