本地主机的 1 秒连接时间与我的 IP 192.168.1.x 的零连接时间

发布于 2024-09-30 05:54:15 字数 742 浏览 1 评论 0原文

我发现连接到本地计算机上运行的开发网络服务器时出现奇怪的行为。

当我连接到 http://192.168.1.14 (我的 IP)一切加载速度都很快(子一个页面 + 20 个资源 200 毫秒,预期结果)。

当我连接到 http://localhost 时,同一页面的加载时间为 5 秒 时间当我使用 Chrome 分析页面时,看到的是:

  • 第 1 页,约 1 秒连接时间(从 0.98 到 1.02 不等),然后加载速度很快
  • 接下来的 3 个资源有约 1 秒连接时间,然后加载速度很快。
  • 接下来的 6 个然后等待约 1 秒的连接时间(在加载最后一组之后),然后快速加载。
  • 此模式会以 6 个资源为一组重复进行,直到所有资源都加载完毕。

对此有什么想法吗? 1 秒的连接时间延迟是从哪里来的?

我引用的是 Google Chrome 开发者工具中提供的资源配置文件图表中的“连接时间”。例如,一项资源显示:

Proxy:      0ms
DNS Lookup: 1ms
Connecting: 1.00s
Sending:    0ms
Waiting:    3ms
Receiving:  2ms

I'm seeing an odd behavior connecting to a development webserver running on my local machine.

When I connect to http://192.168.1.14 (my ip) everything loads fast (sub 200ms for a page + 20 resources, an expected result).

When I connect to http://localhost I get 5 second load times for the same page and what I see when I profile the page using Chrome is:

  • 1st page, ~1 sec connection time (varies from 0.98 to 1.02), then loads fast
  • The next 3 resources have a ~1 sec connection time then load fast.
  • The next 6 then wait ~1 sec connection time (after the last group loaded) then load fast.
  • This pattern repeats its self in batches of 6 resources until everything is loaded.

Any ideas on this? Where could the 1 sec connection time delay be coming from?

I'm referencing "Connection Time" from the resource profile graph provided in the Google Chrome Developer Tools. For example, one resource shows:

Proxy:      0ms
DNS Lookup: 1ms
Connecting: 1.00s
Sending:    0ms
Waiting:    3ms
Receiving:  2ms

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

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

发布评论

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

评论(3

痴情换悲伤 2024-10-07 05:54:15

我最近也遇到了类似的问题。

问题是我在 Windows 的代理设置中配置了代理服务器,即使我明确启用了“绕过本地地址的代理服务器”选项,每个请求也会通过代理。显然这个设置不起作用或者没有达到我的预期。

因此,我继续在高级代理设置中为 localhost 配置了一个例外。现在,我的开发服务器上的所有内容加载速度都非常快。

I had a similar problem recently.

The problem was that I had configured a proxy server in Windows' proxy settings and every request went through the proxy even though I had explicitly enabled the option "Bypass proxy server for local addresses". Apparently this setting was not working or didn't do what I expected.

So I went ahead and configured an exception for localhost in the advanced proxy settings. Now everything from my development server loads pretty fast.

总以为 2024-10-07 05:54:15

直接尝试 127.0.0.1 时会发生什么?我想象它可能是这样一个事实:仍然需要将localhost转换为127.0.0.1,无论是DNS服务器还是您的/etc/hosts文件或黄页服务。

如果 127.0.0.1 很快,我会说这是翻译延迟,在这种情况下,下一步是找出正在翻译的内容。

如果速度很慢,我会查看应用程序服务器或网络服务器日志。 Apache,如果您正在使用它,它是迄今为止构建的仅有的两个可无限配置的应用程序之一,另一个当然是 Emacs :-)

What happens when you try 127.0.0.1 directly? I imaging it could be the fact that something still has to translate localhost into 127.0.0.1 be it a DNS server or your /etc/hosts file or the yellow-pages service.

If 127.0.0.1 is fast, I would say it's a translation delay in which case the next step is to figure out what's doing the translation.

If it's slow, I'd be looking at the appserver or webserver logs. Apache, if that's what you're using, is one of the only two infinitely-configurable applications ever built, the other being Emacs, of course :-)

书间行客 2024-10-07 05:54:15

我找到的唯一解决方案是添加主机文件条目并通过主机文件条目引用本地网站。由于某种无法解释的原因,这会实时呈现页面。

The only solution I found was adding a host file entry and referencing the local website through the host file entry. For some inexplicable reason, this rendered the page in real time.

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