使用使用环回地址的TCP/IP套接字进行IPC时,常见的网络堆栈是否跳过将消息放入低级PDU中的框架? [英] When doing IPC using TCP/IP sockets using the loopback address, do common networking stacks skip framing the message in lower-level PDUs?
问题描述
在某些环境(例如Java)中,很自然地使用TCP/IP套接字使用本地主机"地址(在IPv4中为127.0.0.1,在IPv6中为:: 1)在同一主机上的进程之间传递消息. (因为Java倾向于不在其API中公开其他IPC机制).
In some environments such as Java, it's natural to use TCP/IP sockets to pass messages between processes on the same host using the 'localhost' address (127.0.0.1 in IPv4, or ::1 in IPv6). (Because Java tends not to expose other IPC mechanisms in its API).
很明显,与通过管道传递消息的IPC或使用共享内存的IPC相比,这有可能比IPC慢很多.
Clearly, this has the potential to be a lot slower than IPC via message passing over pipes, or IPC using shared-memory.
另一方面,如果TCP/IP网络堆栈意识到连接的两端都在回送接口上,则它可能能够进行相当多的优化,因此与使用管道相比,效率可能不会有太大差异
On the other hand, if the TCP/IP networking stack realised that both ends of the connection were on the loopback interface, it might be able to do a fair bit of optimisation so that the efficiency might not differ much from using pipes.
但是常见的操作系统(Windows,Linux)是否在其TCP/IP堆栈中实现了这种优化?
But do common operating systems (Windows, Linux) implement such optimisations in their TCP/IP stacks?
推荐答案
是.当收到到回送地址(127.x.x.x)的数据包/数据时,TCP/IP的IP层使用回送路由将数据包路由到其自身.
Yes. When a packet/data to a Loopback address(127.x.x.x) is received, the IP layer of the TCP/IP uses the Loopback route to route the packet to itself.
回拨路线
网络目标||网络掩码|| 网关||界面||公制
Network Destination || Netmask || Gateway || Interface || Metric
127.0.0.0 |||||||||||||||||||||||| 255.0.0.0 || 127.0.0.1 || 127.0.0.1 || 1
127.0.0.0 |||||||||||||||||||||| 255.0.0.0 || 127.0.0.1|| 127.0.0.1 || 1
在将其路由到itef之后,借助协议控制块(每个连接数据结构)在TCP/UDP层上,将标识相应的套接字及其所有者进程以传递数据包/数据.
After routing it to itsef, at TCP/UDP layer with the help of protocol control blocks(per connection data structure) the corresponding socket and its owner process will be identified to deliver the packet/data.
最重要的是,将避免在OSI模型的数据链路层和物理层执行所有任务.
Bottom line, All the tasks at Data Link layers and Physical layers(of OSI Model) will be avoided.
这篇关于使用使用环回地址的TCP/IP套接字进行IPC时,常见的网络堆栈是否跳过将消息放入低级PDU中的框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!