建议的 Ping 和 URL 连接超时是多少?

发布于 2024-08-24 09:11:36 字数 179 浏览 2 评论 0原文

我目前正在做一些网络编程,并且有几个关于超时的问题。

执行 ping 操作时是否有建议的超时时间?

另外,进行 URL 连接时是否有建议的超时时间?

编辑:就我而言,通过 ping,我只是想查看设备是否连接到网络。通过 URL 连接,我尝试打开一个 URL 并从中获取文本。

谢谢

I am currently doing some network programming and had a couple questions concerning timeouts.

Is there a recommended timeout in doing a ping?

Also, is there a recommended timeout in doing a URL connection?

Edit: In my case, with the ping, I am just trying to see if a device is connected to the network. With the URL connection, I am trying to open a URL and get the text from it.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情感失落者 2024-08-31 09:11:36

这取决于您要连接的位置。

举个例子:如果您连接到同一数据中心甚至同一机架中的另一个盒子,则只有很少的跳转(路由器、交换机、防火墙等),并且通常应在一秒钟内建立连接 - 因此不需要30 秒超时(我将其设置为 5 秒)。

如果你连接到另一个大陆的盒子,那就完全不同了。数据包丢失、路由和连接拥挤可能会减慢连接速度。 30 秒或 60 秒的超时听起来很公平。

此外,您应该考虑您的客户是否真的想等待 60 秒。再举一个例子,如果您连接到 Web 服务以便处理来自用户的 HTTP 请求。等待 60 秒没有多大意义,因为用户无论如何都会取消/离开请求。此外,这种阻塞服务调用可能会导致大量等待线程填满服务器的线程池 - 这不是一件好事。在这种情况下,我会将超时设置为 10 秒,这样一旦 Web 服务变慢,就会冒着向用户抛出“服务不可用”或类似页面的风险。

This depends on the where you're going to connect to.

To give an example: if you connect to another box in the same data center or even same rack, there are only few jumps (routers, switches, firewalls, ...) and connections should usually be established under a second - hence no need for a 30 second timeout (I'd set it to 5 seconds).

If you connect to a box on another continent, that's a totally different story. Packet loss, crowded routes and connections may slow down the connection. A timeout of 30s or 60s sounds fair.

Additionally, you should consider if you're client really wants to wait for 60 seconds. To give another example, if you connect to a web service in order to serve an HTTP request from a user. Waiting 60 seconds won't make much sense as the user will cancel/leave the request anyway. Furthermore, such blocking service calls might lead to a lot of waiting threads filling up the thread pool of your server - not a good thing. In this case, I'd set the timeout to 10 seconds and rather risk some "service not available" or similar page being thrown at the user as soon as the web service becomes slow.

魔法少女 2024-08-31 09:11:36

一般来说,我为请求设置了 60 秒的超时(如果您通过请求流式传输许多 MB 的文件,则该超时会有所不同)。

有两种类型的 ping。主动 ping,您在请求时实际 ping 可 ping 的组件,而被动 ping,您在后台 ping 组件,并在请求时仅返回缓存的状态。在我的应用程序中,我仍然将这些超时设置为 60 秒,但如果您认为需要快速失败,请随意设置较小的数字。

In general I set a timeout of 60 seconds for a request (This varies if you are streaming many MB of files via a request).

There are two types of pings. Active pings where you actually ping a pingable component when requested and Passive pings where you ping a component in the background and just return a cached status when requested. In my application I still set these timeouts at 60s but if you think you want fail-fast feel free to set a smaller number.

最偏执的依靠 2024-08-31 09:11:36

您期望您的网络表现如何?这将决定您如何看待连接的行为以及您预计何时超时。

例如,您的 ping 将执行多少次网络跳转?在正常情况下这些设备的负载有多大?

How do you expect your network to behave ? That will dictate how you regard the connections to behave and when you'd expect a timeout.

e.g. how many network jumps will your ping perform over ? How loaded are those devices in a normal scenario ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文