OpenAPI Generator(C#,.NET6) - 在某些条件下的HTTP请求极慢。
我使用OpenAPI生成器为Things board Rest API生成C#客户端。 然后,我使用此客户端来构建一个应用程序,以自动创建设备并将遥测数据写入Thingsboard。
当我在家工作并通过VPN连接到我的公司网络时,我的应用程序工作正常,而且相当快。但是,当我在网站上工作时,我注意到对Thingsboard的每个HTTP请求(在我们公司网络中托管在VM上)实际上(最多30秒),我不知道,为什么。我调用哪个API功能或端点都没关系,它们都很慢。
我已经对此进行了调试,以至于我可以确保延迟是在此功能调用中引起的,该函数在restsharp.restclient
中实现了:
response = await client.ExecuteAsync<T>(req, cancellationToken).ConfigureAwait(false);
因为这在自动生成的客户端代码中深处,所以真的不知道如何再调试。我注意到的一件事是,此问题100%仅限于应用程序本身,而不是我的整个系统/连接。例如,当我通过Postman或直接在浏览器中调用API时,它可以正常工作,并且在不到1秒钟内得到响应。
是什么可能导致这个问题,我该如何进行进一步调试?
I used OpenAPI Generator to generate a C# client for the Thingsboard REST API.
I then used this client to build an application for automatically creating devices and writing telemetry data into Thingsboard.
When I work from home and connect to my company network via a VPN, my application works just fine and is reasonably fast. However, when I work on site I noticed that every single http request towards Thingsboard (hosted on a VM in our company network) takes literally forever (up to 30 seconds) and I have no idea, why. It does not matter which API function or endpoint I call, they are all slow.
I already debugged this to the point where I can say for sure that the delay is caused somewhere inside this function call which is implemented in RestSharp.RestClient
:
response = await client.ExecuteAsync<T>(req, cancellationToken).ConfigureAwait(false);
As this is deep inside the auto generated client code, I don't really know how to debug this any further. One important thing I noticed is that this problem is 100% limited to the application itself, and not to my whole system/connection. For example, when I call the API via Postman or directly in my browser, it works just fine and I get a response within less than 1 second.
What could be causing this problem and how can I debug it further?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于服务器位置所在。如果在您的办公室里,它将提供快速的回应。如果服务器位于一个国家,而您在另一个国家,它将给出缓慢的响应
It Depend on the where server location is. If it's in your office it will give fast Response. If Server is in one country and you are in another country it will give slow response