UDP和TCP的优缺点比较

UDP vs TCP, how much faster is it?

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

 

其中这段话是重点:

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

 

之前网上很多老文章都说关闭Nagle算法可以提高tcp通信性能,但是这应该看场景,如果客户端和服务端之前的小包消息频率不高,禁用nagle确实可以提高性能,但是反之:客户端服务端之间大部分时间都不是空闲而是不停收发消息,那么禁用nagle就降低性能了,如果是分布式服务器的应用场景,各个服务器之间用tcp通信,那么肯定不能禁用nagle,毕竟服务器压力较大时内部通信肯定极度频繁。

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值