When using tool to return images data, it will be extremely slow #12234

Closed
opened 2026-02-21 19:06:29 -05:00 by yindo · 1 comment
Owner

Originally created by @QunBB on GitHub (Mar 27, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.1.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Create a chatflow app, add the ComfyUI tool node, and finally return the image.

Some analysis about my test

the problem lies in the function api/core/plugin/manager/base.py/_stream_request and something wrong in plugin_daemon sse.
_stream_request receive the first response very slowly with stream mode, and i try to change it without stream mode, then it is behaving normally.

✔️ Expected Behavior

The plugin_daemon log:
[GIN] 2025/03/27 - 09:07:01 | 200 | 4.998979025s | 192.168.xxx.xxx | POST "/plugin/fe02ab38-51c9-49e1-8e0f-717efab59378/dispatch/tool/invoke"

The app should take about 5-6s to complete.

Actual Behavior

Image
Originally created by @QunBB on GitHub (Mar 27, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.1.3 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce **Create a chatflow app, add the ComfyUI tool node, and finally return the image.** ### Some analysis about my test the problem lies in the function [api/core/plugin/manager/base.py/_stream_request](https://github.com/langgenius/dify/blob/main/api/core/plugin/manager/base.py#L72) and something wrong in plugin_daemon sse. `_stream_request` receive the first response very slowly with stream mode, and i try to change it without stream mode, then it is behaving normally. ### ✔️ Expected Behavior The plugin_daemon log: [GIN] 2025/03/27 - 09:07:01 | 200 | **4.998979025s** | 192.168.xxx.xxx | POST "/plugin/fe02ab38-51c9-49e1-8e0f-717efab59378/dispatch/tool/invoke" **The app should take about 5-6s to complete.** ### ❌ Actual Behavior <img width="399" alt="Image" src="https://github.com/user-attachments/assets/a9f5e6f6-5867-4dae-aa7a-88d5b552c98d" />
yindo closed this issue 2026-02-21 19:06:29 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 27, 2025):

There are a few similar discussions regarding slow response times when using streaming mode in Dify:

  1. Using post to call dify chatflow's API (enable streaming), the response is very slow [1].
  2. The API service that uses DIFY uses the streaming stream, but the result is that it waits for a long time to return at the same time, what is the reason for this? [2].
  3. When publishing Api, ''/chat-messages'' api responds slowly with data in streaming mode [3].

These discussions are unsolved, but they might provide some insights or potential workarounds.

Regarding your issue, the _stream_request function in api/core/plugin/manager/base.py is designed to handle streaming requests by processing the response incrementally. This can sometimes lead to slower initial response times compared to non-streaming mode, where the entire response is processed at once [4].

To potentially improve performance, you might consider adjusting configuration settings related to timeouts in your .env file, such as HTTP_REQUEST_MAX_READ_TIMEOUT and HTTP_REQUEST_MAX_WRITE_TIMEOUT, to better handle streaming requests [5].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 27, 2025): <!-- Answer --> There are a few similar discussions regarding slow response times when using streaming mode in Dify: 1. [Using post to call dify chatflow's API (enable streaming), the response is very slow](https://github.com/langgenius/dify/discussions/16602) <sup>[[1]](https://github.com/langgenius/dify/discussions/16602)</sup>. 2. [The API service that uses DIFY uses the streaming stream, but the result is that it waits for a long time to return at the same time, what is the reason for this?](https://github.com/langgenius/dify/discussions/13700) <sup>[[2]](https://github.com/langgenius/dify/discussions/13700)</sup>. 3. [When publishing Api, ''/chat-messages'' api responds slowly with data in streaming mode](https://github.com/langgenius/dify/discussions/8671) <sup>[[3]](https://github.com/langgenius/dify/discussions/8671)</sup>. These discussions are unsolved, but they might provide some insights or potential workarounds. Regarding your issue, the `_stream_request` function in `api/core/plugin/manager/base.py` is designed to handle streaming requests by processing the response incrementally. This can sometimes lead to slower initial response times compared to non-streaming mode, where the entire response is processed at once <sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/plugin/manager/base.py)</sup>. To potentially improve performance, you might consider adjusting configuration settings related to timeouts in your `.env` file, such as `HTTP_REQUEST_MAX_READ_TIMEOUT` and `HTTP_REQUEST_MAX_WRITE_TIMEOUT`, to better handle streaming requests <sup>[[5]](https://github.com/langgenius/dify/issues/14416)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/250f8775-581a-4914-ace6-e6380f1996dd?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/250f8775-581a-4914-ace6-e6380f1996dd?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/250f8775-581a-4914-ace6-e6380f1996dd?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/250f8775-581a-4914-ace6-e6380f1996dd?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/250f8775-581a-4914-ace6-e6380f1996dd?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/250f8775-581a-4914-ace6-e6380f1996dd?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/250f8775-581a-4914-ace6-e6380f1996dd?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12234