dify icon indicating copy to clipboard operation
dify copied to clipboard

HTTP Request is slowly

Open pengzhen-developer opened this issue 7 months ago • 14 comments

Self Checks

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

Dify version

1.2.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

HTTP is slowly.

This situation occurs intermittently. It seems that it will be very slow every 30 seconds, but it is normal at other times.

What happened between these two time points? Why was it so slow?

  1. 2025-04-10 14:40:46.891
  2. 2025-04-10 14:41:02.992
  • Screen:

Image

  • Log:
nginx-1          | ***.**.198.39 - - [10/Apr/2025:14:40:46 +0000] "POST /console/api/apps/e5238152-ab4c-4aaa-b75c-0b71171255be/workflows/draft HTTP/1.1" 200 138 "http://***.**.4.18:8081/app/e5238152-ab4c-4aaa-b75c-0b71171255be/workflow" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" "-"
api-1            | Inputs:
api-1            | Process Data: {'request': 'GET /fusion_pre_inquiry_manage/dept/filterDepts?excludeLabel=男性科室&appKey=e3d1dc8297792e13d34418b27408ab98 HTTP/1.1\r\nHost: ***.**.4.18\r\n\r\n'}
api-1            | Outputs: {'status_code': 200, 'body': '{"data":[{"areaCode":"主园区","areaName":"主园区","deptCode":"0000","deptName":"儿童呼吸科MDT门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0203","deptName":"儿内科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0205","deptName":"新生儿科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0207","deptName":"产科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0211","deptName":"妇科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0215","deptName":"生殖科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0217","deptName":"外科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0218","deptName":"甲状腺乳腺外科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0219","deptName":"成人内科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0221","deptName":"耳鼻喉科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0222","deptName":"口腔科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0225","deptName":"急诊科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0226","deptName":"中医科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0231","deptName":"眼科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0232","deptName":"康复理疗科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0305","deptName":"超声诊断科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0401","deptName":"儿保科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0402","deptName":"医疗美容科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0403","deptName":"妇保科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0509","deptName":"皮肤性病科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0520","deptName":"中西医结合科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0521","deptName":"优生遗传中心"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0573","deptName":"儿内科过敏"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0703","deptName":"妇科II"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0711","deptName":"骨科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0738","deptName":"肠道门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0744","deptName":"盆底康复中心"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0756","deptName":"儿童睡眠专病门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"0760","deptName":"神经外科门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1111","deptName":"助产士门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1137","deptName":"成人普外科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1146","deptName":"成人重症医学科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1169","deptName":"健康体检中心"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1175","deptName":"手术麻醉科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1177","deptName":"疼痛亚专科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1211","deptName":"妇科宫腔镜中心"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1212","deptName":"儿童康复科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1213","deptName":"儿童神经内科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1216","deptName":"肿瘤科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1219","deptName":"成人急诊外科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1226","deptName":"妇儿介入诊疗专科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1231","deptName":"助产士门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1238","deptName":"新冠中医康复门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1239","deptName":"新冠肺康复门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1241","deptName":"中医科亚健康调理门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1242","deptName":"儿童营养专科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1247","deptName":"母乳喂养门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1250","deptName":"营养科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1255","deptName":"成人泌尿外科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1259","deptName":"输血科门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1266","deptName":"儿童哮喘、慢咳/呼吸康复门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1267","deptName":"中心静脉导管维护门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1268","deptName":"中医护理门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1269","deptName":"中西医结合科亚健康调理门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1272","deptName":"成人心血管病及血栓专科门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1274","deptName":"早孕门诊"},{"areaCode":"主园区","areaName":"主园区","deptCode":"1280","deptName":"儿童泌尿外科"},{"areaCode":"主园区","areaName":"主园区","deptCode":"2222","deptName":"新生儿护理门诊"}],"message":"success","status":200}', 'headers': {'server': 'nginx/1.27.2', 'date': 'Thu, 10 Apr 2025 14:39:13 GMT', 'content-type': 'application/json;charset=UTF-8', 'vary': 'origin,access-control-request-method,access-control-request-headers,accept-encoding', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate', 'pragma': 'no-cache', 'expires': '0', 'content-encoding': 'gzip', 'cache-status': '123ffb4ed41f;detail=mismatch', 'transfer-encoding': 'chunked', 'via': '1.1 123ffb4ed41f (squid/6.10)', 'connection': 'keep-alive'}, 'files': []}
api-1            | Metadata:
api-1            |
api-1            | [NodeRunStartedEvent]
api-1            | Node ID: answer
api-1            | Node Title: 直接回复
api-1            | Type: answer
api-1            |
api-1            | [NodeRunSucceededEvent]
api-1            | Node ID: answer
api-1            | Node Title: 直接回复
api-1            | Type: answer
api-1            | Inputs:
api-1            | Process Data:
api-1            | Outputs: {'answer': '1', 'files': []}
api-1            | Metadata:
api-1            |
api-1            | [GraphRunSucceededEvent]
api-1            | 2025-04-10 14:40:46.821 INFO [Thread-67 (process_request_thread)] [_internal.py:97] - ***18.0.10 - - [10/Apr/2025 14:40:46] "POST /console/api/apps/e5238152-ab4c-4aaa-b75c-0b71171255be/workflows/draft HTTP/1.1" 200 -
api-1            |
api-1            | [GraphRunStartedEvent]
api-1            |
api-1            | [NodeRunStartedEvent]
api-1            | Node ID: 1744292656516
api-1            | Node Title: 开始
api-1            | Type: start
api-1            |
api-1            | [NodeRunSucceededEvent]
api-1            | Node ID: 1744292656516
api-1            | Node Title: 开始
api-1            | Type: start
api-1            | Inputs: {'sys.query': '1', 'sys.files': [], 'sys.conversation_id': 'd96136a9-dbf4-4ac9-a0e1-e47eceee5c8d', 'sys.user_id': '7fd15bfc-d120-4783-b63e-43f0a2bcc6f6', 'sys.dialogue_count': 9, 'sys.app_id': 'e5238152-ab4c-4aaa-b75c-0b71171255be', 'sys.workflow_id': '40fd79e4-c900-436c-ba03-e1abe2953a9b', 'sys.workflow_run_id': '94c3cb42-a8cf-4539-bf55-6c0030b89b29'}
api-1            | Process Data:
api-1            | Outputs: {'sys.query': '1', 'sys.files': [], 'sys.conversation_id': 'd96136a9-dbf4-4ac9-a0e1-e47eceee5c8d', 'sys.user_id': '7fd15bfc-d120-4783-b63e-43f0a2bcc6f6', 'sys.dialogue_count': 9, 'sys.app_id': 'e5238152-ab4c-4aaa-b75c-0b71171255be', 'sys.workflow_id': '40fd79e4-c900-436c-ba03-e1abe2953a9b', 'sys.workflow_run_id': '94c3cb42-a8cf-4539-bf55-6c0030b89b29'}
api-1            | Metadata:
api-1            |
api-1            | [NodeRunStreamChunkEvent]
api-1            | Node ID: 1744292656516
api-1            | Metadata:
api-1            | 1
api-1            | [NodeRunStartedEvent]
api-1            | Node ID: 1744294730348
api-1            | Node Title: HTTP 请求 2
api-1            | Type: http-request
api-1            | 2025-04-10 14:40:46.891 INFO [Thread-68 (process_request_thread)] [_internal.py:97] - ***18.0.10 - - [10/Apr/2025 14:40:46] "POST /console/api/apps/e5238152-ab4c-4aaa-b75c-0b71171255be/advanced-chat/workflows/draft/run HTTP/1.1" 200 -
api-1            | 2025-04-10 14:41:02.992 INFO [Thread-69 (_generate_worker)] [_client.py:1038] - HTTP Request: GET http://***.**.4.18/fusion_pre_inquiry_manage/dept/filterDepts?excludeLabel=%E7%94%B7%E6%80%A7%E7%A7%91%E5%AE%A4&appKey=e3d1dc8297792e13d34418b27408ab98 "HTTP/1.1 200 OK"
nginx-1          | ***.**.198.39 - - [10/Apr/2025:14:41:03 +0000] "POST /console/api/apps/e5238152-ab4c-4aaa-b75c-0b71171255be/advanced-chat/workflows/draft/run HTTP/1.1" 200 17411 "http://***.**.4.18:8081/app/e5238152-ab4c-4aaa-b75c-0b71171255be/workflow" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" "-"
ssrf_proxy-1     | 1744296062.992  16014 ***18.0.8 TCP_MISS/200 1416 GET http://***.**.4.18/fusion_pre_inquiry_manage/dept/filterDepts? - HIER_DIRECT/***.**.4.18 application/json
sandbox-1        | [GIN] 2025/04/10 - 14:41:11 | 200 |      34.299µs |             ::1 | GET      "/health"

✔️ Expected Behavior

Response quikly

❌ Actual Behavior

Response slowly

pengzhen-developer avatar Apr 10 '25 14:04 pengzhen-developer

你好 @pengzhen-developer!我是一个可以帮助你解决bug、回答问题并成为贡献者的机器人。在等待人类维护者的同时,我会尽力帮助你。如果你有任何问题,请随时告诉我!

I found a similar discussion regarding slow HTTP requests in Dify, which is still open. The discussion suggests optimizing performance by adjusting timeout settings in the configuration. The default settings include max_connect_timeout, max_read_timeout, and max_write_timeout, which can be tailored to your needs. Additionally, integrating Dify with external Ops tools like LangSmith and Langfuse can help diagnose performance issues by providing comprehensive tracking and evaluation capabilities [1].

For your specific issue, you might want to check these timeout settings and consider using external tools for better observability and debugging. If the problem persists intermittently, it could be related to network conditions or server load at specific times.

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] avatar Apr 10 '25 14:04 dosubot[bot]

If need other info, please feel free to contact me.

pengzhen-developer avatar Apr 10 '25 14:04 pengzhen-developer

Some additional information that may be useful is that every time the HTTP response is slow, it takes about 16 seconds.

pengzhen-developer avatar Apr 11 '25 00:04 pengzhen-developer

What we've experienced is that, in preview mode, it runs fast, 3s maybe. but in api mode, it costs 20s...

allanwakes avatar Apr 11 '25 09:04 allanwakes

What we've experienced is that, in preview mode, it runs fast, 3s maybe. but in api mode, it costs 20s...

Maybe 16 + 3 = 20s。^_^。

After multiple tests, it can be stably reproduced that there is a freeze every 30 seconds, and the duration of each freeze is 16 seconds.

pengzhen-developer avatar Apr 11 '25 09:04 pengzhen-developer

What we've experienced is that, in preview mode, it runs fast, 3s maybe. but in api mode, it costs 20s...

@allanwakes

You can try to use the requests library in Python to make API calls within the [Code Execution] node.

Like this:

import requests


def main(arg1=None, arg2=None):
    try:
        r = requests.get("https://xxx")
        r.raise_for_status()
        result = r.text
    except requests.RequestException:
        result = '错误'

    print(result)
    return {
        "result": result
    }

pengzhen-developer avatar Apr 11 '25 10:04 pengzhen-developer

I also encountered this problem where HTTP requests cannot be accessed externally

AlexYuan997 avatar Apr 12 '25 10:04 AlexYuan997

If you encounter a 20-second delay in HTTP requests in an internal network environment, it may be caused by the domain configuration in ssrf_proxy. You can disable DNS resolution by configuring:

ssrf_proxy/squid.conf.template: dns_nameservers

hizhujianfeng avatar Apr 19 '25 16:04 hizhujianfeng

我也是一模一样的情况,已尝试在 squid.conf.template 添加:dns_nameservers none 但是没用

ft4710403 avatar Apr 22 '25 09:04 ft4710403

vi /etc/resolv.conf,change your nameserver(DNS ADDRESS),if your dify is deployed in a none-internet environment

1012747520 avatar Apr 27 '25 07:04 1012747520

It seems like Dify will try to reverse resolve IP addresses, which in an internal network environment, if the DNS is unreachable, will result in timeout. No matter for a HTTP node or a Code node. Try add these to dify/docker/ssrf_proxy/squid.conf.template to shorten the timeout period. ignore_unknown_nameservers on dns_timeout 1 seconds dns_retransmit_interval 1 seconds dns_defnames off Then restart ssrf_proxy container. It worked for me as a walkaround. To completely solve it, I think it may require an accessible DNS.

Image

zhangjizhong-86 avatar May 16 '25 09:05 zhangjizhong-86

@pengzhen-developer Has this problem been solved? I also encountered the same problem

uncleunclelu avatar May 19 '25 06:05 uncleunclelu

It seems like Dify will try to reverse resolve IP addresses, which in an internal network environment, if the DNS is unreachable, will result in timeout.看起来 Dify 将尝试反向解析 IP 地址,在内部网络环境中,如果 DNS 无法访问,将导致超时 No matter for a HTTP node or a Code node.无论是 HTTP 节点还是代码节点。 Try add these to dify/docker/ssrf_proxy/squid.conf.template to shorten the timeout period.尝试将这些添加到 dify/docker/ssrf_proxy/squid.conf.template 中以缩短超时时间。 ignore_unknown_nameservers on dns_timeout 1 seconds dns_retransmit_interval 1 seconds dns_defnames off Then restart ssrf_proxy container.然后重启 ssrf_proxy 容器。 It worked for me as a walkaround.这对我来说是一个可行的解决方法。 To completely solve it, I think it may require an accessible DNS.要完全解决这个问题,我认为可能需要可访问的 DNS。

Image

秀儿

bigevolution avatar May 19 '25 07:05 bigevolution

@pengzhen-developer Has this problem been solved? I also encountered the same problem这个问题解决了吗?我也遇到了同样的问题

It seems like Dify will try to reverse resolve IP addresses, which in an internal network environment, if the DNS is unreachable, will result in timeout.Dify 似乎会尝试反向解析 IP 地址,在内部网络环境中,如果 DNS 无法访问,就会导致超时。 No matter for a HTTP node or a Code node.无论是 HTTP 节点还是代码节点。 Try add these to dify/docker/ssrf_proxy/squid.conf.template to shorten the timeout period.尝试将这些添加到 dify/docker/ssrf_proxy/squid.conf.template 以缩短超时时间。 ignore_unknown_nameservers on dns_timeout 1 seconds dns_retransmit_interval 1 seconds dns_defnames off Then restart ssrf_proxy container.然后重新启动 ssrf_proxy 容器。 It worked for me as a walkaround.对我来说,这是一种解决方法。 To completely solve it, I think it may require an accessible DNS.为了彻底解决这个问题,我认为可能需要一个可访问的 DNS。

Image

maybe resolve.

pengzhen-developer avatar May 19 '25 08:05 pengzhen-developer

Has this problem been solved? I also encountered the same problem

It seems like Dify will try to reverse resolve IP addresses, which in an internal network environment, if the DNS is unreachable, will result in timeout. No matter for a HTTP node or a Code node. Try add these to dify/docker/ssrf_proxy/squid.conf.template to shorten the timeout period. ignore_unknown_nameservers on dns_timeout 1 seconds dns_retransmit_interval 1 seconds dns_defnames off Then restart ssrf_proxy container. It worked for me as a walkaround. To completely solve it, I think it may require an accessible DNS.

Image

Has this problem been solved? I also encountered the same problem in the intranet(no internet)

SpencerKD avatar Jun 16 '25 06:06 SpencerKD

t seems like Dify will try to reverse resolve IP addresses, which in an internal network environment, if the DNS is unreachable, will result in timeout. No matter for a HTTP node or a Code node. Try add these to dify/docker/ssrf_proxy/squid.conf.template to shorten the timeout period. ignore_unknown_nameservers on dns_timeout 1 seconds

Maybe it is the way to solve this problem. We deployed the dify in our intranet and we config this template file like this then the API not time out. Bingo!

SpencerKD avatar Jun 17 '25 06:06 SpencerKD

Please refer to https://github.com/langgenius/dify/issues/17811#issuecomment-2886134421

pengzhen-developer avatar Jun 18 '25 02:06 pengzhen-developer

我也是一模一样的情况,已尝试在 squid.conf.template 添加:dns_nameservers none 但是没用

能详细的说说你是如何禁用的吗

holdbelief avatar Jul 24 '25 06:07 holdbelief

Problem Analysis: In an internal network environment where DNS resolution is unavailable or restricted, the Squid proxy configured with domain-based access control will attempt to resolve marketplace.dify.ai through DNS during every request. This leads to connection timeouts when DNS queries fail.

Solution: To bypass DNS dependency in restricted environments:

1.Locate the Squid configuration template at docker/ssrf_proxy/squid.conf.template 2.Comment out the domain-based access control rules by adding # at the beginning of these lines: #acl allowed_domains dstdomain .marketplace.dify.ai #http_access allow allowed_domains 3.Save the file and restart the Squid service

dickenschen avatar Jul 28 '25 08:07 dickenschen

Problem Analysis: In an internal network environment where DNS resolution is unavailable or restricted, the Squid proxy configured with domain-based access control will attempt to resolve marketplace.dify.ai through DNS during every request. This leads to connection timeouts when DNS queries fail.

Solution: To bypass DNS dependency in restricted environments:

1.Locate the Squid configuration template at docker/ssrf_proxy/squid.conf.template 2.Comment out the domain-based access control rules by adding # at the beginning of these lines: #acl allowed_domains dstdomain .marketplace.dify.ai #http_access allow allowed_domains 3.Save the file and restart the Squid service

It works for me. Thx a lot.

chenry-me avatar Aug 06 '25 08:08 chenry-me

Problem Analysis:  问题分析: In an internal network environment where DNS resolution is unavailable or restricted, the Squid proxy configured with domain-based access control will attempt to resolve marketplace.dify.ai through DNS during every request. This leads to connection timeouts when DNS queries fail. 在 DNS 解析不可用或受限的内部网络环境中,配置有基于域的访问控制的 Squid 代理将在每次请求期间尝试通过 DNS 解析 marketplace.dify.ai。当 DNS 查询失败时,这会导致连接超时。

Solution:  解决方法: To bypass DNS dependency in restricted environments: 要在受限环境中绕过 DNS 依赖性,请执行以下操作:

1.Locate the Squid configuration template at docker/ssrf_proxy/squid.conf.template1.在 docker/ssrf_proxy/squid.conf.template 中找到 Squid 配置模板 2.Comment out the domain-based access control rules by adding # at the beginning of these lines: 2.通过在以下行的开头添加#注释掉基于域的访问控制规则: #acl allowed_domains dstdomain .marketplace.dify.ai #acl allowed_domains dstdomain . marketplace.dify.ai #http_access allow allowed_domains #http_access allowed_domains 3.Save the file and restart the Squid service 3.保存文件并重新启动 Squid 服务

thx!

JinCheng666 avatar Sep 14 '25 10:09 JinCheng666