Is there a best practice when the LLM response is too slow? #33079
Replies: 2 comments 11 replies
-
Beta Was this translation helpful? Give feedback.
-
|
Yes, there are several best practices to mitigate slow LLM response issues in Dify. The symptoms you're describing (connection pool exhaustion, Key Timeout Settings to Configure: Add these to your # Increase Gunicorn timeout (default 200s, recommend 360s+)
GUNICORN_TIMEOUT=360
# Application-level timeouts
APP_MAX_EXECUTION_TIME=1200
WORKFLOW_MAX_EXECUTION_TIME=1200
# Plugin daemon timeout (if using v1.10.0+)
DIFY_BACKWARDS_INVOCATION_READ_TIMEOUT=600000 # 10 minutes in ms
# Nginx timeouts (critical for streaming)
NGINX_PROXY_READ_TIMEOUT=3600s
NGINX_PROXY_SEND_TIMEOUT=3600sCritical Nginx Configuration: If you're using a reverse proxy, ensure these settings to prevent HTTP/2 protocol errors: location /api {
proxy_http_version 1.1; # Required - HTTP/2 breaks SSE
proxy_set_header Connection '';
proxy_buffering off; # Critical for streaming
proxy_cache off;
}Connection Pool Tuning: If you're hitting database connection limits, reduce SQLALCHEMY_POOL_SIZE=20
SQLALCHEMY_MAX_OVERFLOW=10Important Limitation: There's a hardcoded 240-second timeout for LLM streaming in agent strategies that cannot be changed via environment variables. If your LLM operations regularly exceed this, you may need to modify the source code in Additional Tips:
To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
When the LLM response is extremely slow, I strongly suspect that Dify spawns and hangs a large number of background threads to handle these tasks.
As users keep retrying and refreshing, the connection pool gets exhausted, triggering numerous exceptions that eventually cause a full page crash. The most obvious symptom is seeing many retries in the F12 dev tools, all ending with
(failed)net::ERR_CONNECTION_RESET.Meanwhile, refreshing the page usually leads to the degraded page showing you're offline like below.

Are there any best practices to mitigate this issue? For example, setting a response timeout for the LLM? Or other ways to optimize these extremely time-consuming processes?
Currently, Dify only freezes the session and response nothing. Even though the response might be compensated into the session after a long wait, it does bring down the entire page. No client can wait this long time.
2. Additional context or comments
No response
Beta Was this translation helpful? Give feedback.
All reactions