为什么Tcp比http快?
我和我的经理讨论过,他说 tcp 比 http 更快,因为 tcp 工作在比 http 更低的层上。
然后我想起了我在大学学过的OSI Model,所以我认为他的意思是因为http在应用层工作,但tcp在传输层(下面2层)工作,所以速度更快...
所以我的问题是:
较低层的工作速度是否比上层更快,因为那里处理数据时需要访问的层数更少两台计算机之间的传输?
如果是这样,这意味着当我们使用 tcp(即使用 WCF)时,通信将从传输层开始=>深入到物理层=>另一台计算机的物理层 =>直到传输层?但我认为数据仍然需要被应用程序理解,所以它仍然需要上升到应用程序层?
提前致谢。
I had a discussion with my manager, he said tcp is faster than http because of tcp is work on layer lower than http.
Then I remember about the OSI Model that I learnt in university, so I think what he meant is because http work on application layer but tcp work on transport layer (which is 2 layers belows) so is faster...
So my questions is:
Is lower layers works faster than upper layers is becasue there is less layers need to access when doing data transfers betweens two computers?
If so, that's mean when we use tcp (i.e with WCF), the commnicuation will be start at transport layers => down to physical layer => another computer's physical layer => up to transport layers? But I throught the data still need to be understand by the application, so it will still has to goes up to Application layer?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TCP 之上总是有一层。问题实际上在于 TCP 之上的内容增加了多少开销。 HTTP 相对来说比较笨重,因为每次传输都需要在请求和响应中包含一堆报头。它还倾向于在无状态模式下使用,其中每个请求/响应使用单独的 TCP 会话。保持活动可以改善每个请求的会话,但不能改善标头。
There is always a layer above TCP. The question is really about how much overhead the stuff above TCP adds. HTTP is relatively chunky because each transmission requires a bunch of header cruft in both the request and the response. It also tends to be used in a stateless mode, whereby each request/response uses a separate TCP session. Keep-alives can ameliorate the session-per-request, but not the headers.
我注意到了 WCF 标签,所以我猜您正在将 NetTcp 与 BasicHttp 进行比较。正如 @Marcelo Cantos 指出的,两者都基于 TCP 协议。
BasicHttpbinding 使用 HTTP 进行传输,而消息首先封装在 XML 中(非常冗长且渴望数据),然后通过 HTTP 发送,使用大量数据作为标头。
相反,NetTcp 使用(专有?)协议,其中消息编码和标头专门设计用于减少带宽使用。
在常见场景中,您不会看到任何差异,但在处理大量请求或大量数据(尤其是二进制数据,必须对其进行编码以适应 XML 从而增加其大小)时,您可能会通过使用获得好处网络 TCP。
I noted the WCF tag, so I guess you're comparing NetTcp to for example BasicHttp. As @Marcelo Cantos pointed out, both drive on the TCP protocol.
Whereas the BasicHttpbinding uses HTTP for transport, a message is first encapsulated in XML (which is pretty verbose and data-eager) and then sent through HTTP, using lots of data for headers.
On the contrary, NetTcp uses a (proprietary?) protocol, where the message encoding and headers are specifically designed to decrease bandwidth usage.
In a common scenario you won't see any difference, but when dealing with lots of requests or larger amounts of data (especially binary data, which has to be encoded to fit in XML which increases its size), you might gain benefits by using NetTcp.
你是对的:TCP 和 HTTP 是在不同层上运行的协议。
一般来说:为了让应用程序利用网络,它们需要在应用程序层运行。任何给定协议的速度取决于它所需的开销。 HTTP 通常在 TCP 上运行,因此它需要 TCP 的所有开销、TCP 下各层的所有开销以及 HTTP 本身所需的所有开销(它有一些相当大的标头)。
在比较 TCP 和 HTTP 的速度时,您实际上是在比较苹果和橘子。比较 TCP、UDP 和其他传输层协议,以及 HTTP、FTP 和其他应用层协议更有意义。
You are correct: TCP and HTTP are protocols that operate on different layers.
In general: in order for applications to utilize networking they need to operate at the application layer. The speed that any given protocol goes depends on the overhead it demands. HTTP typically operates over TCP, so it requires all of the overhead of TCP, all of the overhead of the layers under TCP, and all the overhead that HTTP requires itself (it has some rather large headers).
You're essentially comparing apples to oranges in comparing the speeds of TCP and HTTP. It makes more sense to compare TCP vs UDP vs other transport layer protocols -- and HTTP vs FTP vs other application layer protocols.