Comparison of advantages and disadvantages of UDP and TCP

UDP vs TCP, how much faster is it?

http://stackoverflow.com/questions/47903/udp-vs-tcp-how-much-faster-is-it

 

This passage is the key point:

In some applications TCP is faster (better throughput) than UDP.

 

This is the case when doing lots of small writes relative to the MTU size. For example, I read an experiment in which a stream of 300 byte packets was being sent over Ethernet (1500 byte MTU) and TCP was 50% faster than UDP.

 

The reason is because TCP will try and buffer the data and fill a full network segment thus making more efficient use of the available bandwidth.

 

UDP on the other hand puts the packet on the wire immediately thus congesting the network with lots of small packets.

 

You probably shouldn't use UDP unless you have a very specific reason for doing so. Especially since you can give TCP the same sort of latency as UDP by disabling the Nagle algorithm (for example if you're transmitting real-time sensor data and you're not worried about congesting the network with lot's of small packets).

 

Many old articles on the Internet have said that turning off the Nagle algorithm can improve tcp communication performance, but this should depend on the scenario. If the frequency of small packet messages between the client and the server is not high, disabling nagle can indeed improve performance, but the opposite: client-server Most of the time is not idle but keeps sending and receiving messages, so disabling nagle will reduce performance. If it is a distributed server application scenario, and each server uses tcp communication, then nagle must not be disabled. After all, the server pressure is relatively high. Internal communication must be extremely frequent in the big time.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326608107&siteId=291194637