Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Tcp faster than http?

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:

  1. Is lower layers works faster than upper layers is becasue there is less layers need to access when doing data transfers betweens two computers?

  2. 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.

like image 201
King Chan Avatar asked Oct 25 '11 22:10

King Chan


3 Answers

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.

like image 93
Marcelo Cantos Avatar answered Oct 17 '22 23:10

Marcelo Cantos


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.

like image 28
CodeCaster Avatar answered Oct 17 '22 22:10

CodeCaster


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.

like image 31
mday299 Avatar answered Oct 17 '22 23:10

mday299