且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

本地域与本地主机的性能

更新时间:2023-01-05 14:50:31

这取决于实现和操作系统.在Windows上,连接到本地IP地址的任何内容(即使它是面向外部的IP)都将经过环回.对于诸如数据包嗅探器之类的应用程序,这是一个已记录的问题,因为您无法嗅探回送. (Windows不会将环回视为设备",它是在网络级别处理的.)但是,在这种情况下,它将对您有利.

This is implementation and operating system dependent. On Windows, anything connecting to a local IP address, even if it is an outside-facing IP, will go over loopback. This is a documented problem for applications such as packet sniffers, because you can't sniff the loopback. (Windows doesn't treat loopback as a "device" -- it is handled at the network level.) However, in this case it would work in your favor.

Linux将遵循路由表中的所有内容,因此,如果路由表不是,则发往本地计算机 的数据包将通过网络发送到本地计算机正确配置.但是,在99%的情况下,将正确配置路由.您的数据包不会通过环回设备,但是TCP/IP堆栈会知道您正在与本地IP联系,并且实际上它会在适当的以太网设备中传出并返回.

Linux, in contrast, will follow whatever you have in your routing table, so packets that are destined to your local machine will go to your local machine over the network if the routing table isn't properly configured. However, in 99% of the cases the routing will be configured properly. Your packets won't go over the loopback device, but the TCP/IP stack will know that you are contacting a local IP and it will virtually go out and back in the proper ethernet device.

在正确配置的环境中,使用域名的唯一瓶颈将是DNS解析时间.联系外部DNS可能会在您的配置中增加额外的延迟.但是,如果将域名添加到/etc/hosts文件中(在Windows中为C:\Windows\System32\drivers\etc\hosts),则系统将跳过DNS解析阶段并直接获取IP,这将使时间成本降低.

In a properly configured environment, the only bottleneck for using a domain name would be DNS resolution time. Contacting an outside DNS can add additional latency into your configuration. However, if you add in the domain name into your /etc/hosts file (C:\Windows\System32\drivers\etc\hosts on Windows), your system will skip the DNS resolution phase and obtain an IP directly, making this time cost moot.