为什么80%的码农都做不了架构师?>>>   

今天发现IM的发送大量消息的TCP报文里有很多

524 22.770505000 192.168.1.26 192.168.2.203 TCP 60 [TCP ZeroWindow] xmpp-client → 18723 [ACK] Seq=1622 Ack=7849 Win=0 Len=0

Window size value: 0

【Calculated window size: 0】

Window size scaling factor: 128

特别查了下做个记录,

window size 官方定义是:在未收到对方确认报文时,发送端能发送的字节(八字节)数;

作用看这个动画:http://histrory.visualland.net/tcp_swnd.html

The easiest way to understand TCP Window size is to observe two people having a conversation. Every so often, the talker will wait for the listener to acknowledge that they have heard everything up to that point. Once the listener acknowledges then the talker begins to talk again. The amount of words spoken before waiting for an acknowledgement from the listener is much like the TCP window size. The official definition of the window size is "the amount of octets that can be transmitted without receiving an acknowledgement from the other side".

Let's assume that the receiver window size is 16,384 bytes which means that the sender can send up to 16,384 bytes before stopping to wait for an acknowledgement. Let's also assume that the maximum segment size is 1024. This means that the sender can send 1024 bytes 16 times before it will stop sending and wait for an acknowledgement. For the sake of simplicity, I will not discuss TCP slow start (Rapid Increase/Multiplicative Decrease), congestion avoidance, congestion window and congestion control etc. As a side note keep in mind that the sender rate is controlled by the min(congestion window, receive window).

So what is the optimum window size that two hosts should agree on? Well there are different school of thoughts, but let's look at one example where the window size is 2 x BDP. What the heck is  BDP you ask? BDP is short for  bandwidth-delay product. Here is how to calculate BDP. Bandwidth times one-way latency.

For example take two hosts connected with 20 Mbps of bandwidth and using PING/ICMP we conclude that the  one-way latency is 20 ms. First let's convert 20 Mbps into bytes which turns out to be  2,621,440 bytes. Take 2,621,440 x .02 equals to approximately 52,428. So 2 x 52,428 =   104,856 bytes, therefore the  optimum window size for 2 hosts with 20 Mbps of bandwidth with a 20 ms one-way latency is 104,856 bytes. That is the sender can send 104,856 bytes of data before the sender must wait for an acknowledgement from the receiver. The reason we are doing 2 x the BDP is because the sender does not have to wait the time it takes for the ACK from the receiver (that he got the first 52428 bytes of data) to come back to the sender. Instead of the sender sitting IDLE for the ACK to come back, the sender can use the ACK travel time (20 ms) to actually send another 52,428 bytes of data.

One problem, the TCP RFC states that the  window size is a  16 bit field which means that the largest window size that can be advertised is 65,536 or 2 ^ 16 or 1111 1111 1111 1111 (16 bits). And as we saw earlier, it is optimum to use 104,856 for the window size. So how do we accomplish this? This is where  window scaling comes into play. It is a TCP option that is sent with the initial TCP 3 way handshake and both sides MUST agree to use this option or else window scaling will not be used. Window scaling basically  bitwise shifts the window size. So let's take a look at a wireshark packet capture to further explain this. Note that window scale option/shift count will be  only be sent/negotiated in the initial 3 way handshake  (SYN, SYN-ACK,ACK).

Flags 0x002 (SYN) - Initial SYN Packet sent by the sender.
Window size value: 8192 or 0010 0000 0000 0000 (16 bits).
Window scale Shift count: 8 - bit-wise shift window size by 8 to the left.
Window multiplier: 256 or 2 ^ shift count which is 2 ^ 8 in this case.

Flags 0x012 (SYN,ACK) - SYN, ACK packet sent by the receiver acknowledging the initial SYN packet.
Window size value: 5840 or 0001 0110 1101 0000 (16 bits).
Window scale Shift count: 7 - bit-wise shift window size by 7 to the left.
Window multiplier: 128 or 2 ^ shift count which is 2 ^ 7 in this case.

Now we are inspecting a packet farther down the conversation. This is a packet sent by 192.168.1.78 who notified the other end to use a shift count of 8.

Window size value: 64 or 0000 0000 0100 0000 (16 bits)
Window size scaling factor: 256 or 2 ^ 8 (as advertised by the 1st packet)
Although the window size states 64, the actual window size is 16,384 (64 * 256) meaning that the other side can send 16,384 bytes of data before stopping to wait for an acknowledgement.

As the conversation between the two hosts continue, the  window size can be narrowed or widen using the widow sizeby specifying the window size value in the 16 bit field however the  window size scaling factor must/will remains the same. For example if the sender wants to make the window size 104,856 the window size would be set as 410 in the 16 bit option field.

410 or 0000 0001 1001 1010 (16 bits) and since it will be shifted 8 to the left, the actual window size will be 104,960 or 0000 0000 0000 0001 1001 1010 0000 0000 (32 bits).

The maximum number of the shift count is 14 per  RFC 1323 which means that the maximum window size can be 1 gigabyte. That is ONE BIG window size!!

Many more articles to come so stay tuned.

Please subscribe/comment/+1 if you like my posts as it keeps me motivated to write more and spread the knowledge.

参考:http://ithitman.blogspot.com/2013/02/understanding-tcp-window-window-scaling.html

linux的window size

How many of you have notice that no matter you have a 100 Mb line, you only get near 2 Mbps, well that is because the TCP window size is only of 32 kB or 64 kB on Linux (depends

on distribution) and 8 kB on M$ Windows.

The TCP window size is the amount of data that will be send on aconnection before a host stops and waits for an acknowledgment. This is used by TCP to prevent congestion.

Ideally it should be:

Window size = Bandwidth x round trip time

#cd /proc/sys/net/core
#ls
message_burst    netdev_max_backlog    rmem_default    wmem_default
message_cost    optmem_max    rmem_max    wmem_max
-------
(The secret are on these files)
/proc/sys/net/core/rmem_default   - default receive window
/proc/sys/net/core/rmem_max       - maximum receive window
/proc/sys/net/core/wmem_default  - default send window
/proc/sys/net/core/wmem_max      - maximum send window

转载于:https://my.oschina.net/greki/blog/264061

关于 TCP window size相关推荐

  1. TCP 协议中的 Window Size与吞吐量

    为了获得最优的连接速率,使用TCP窗口来控制流速率(flow control),滑动窗口就是一种主要的机制.这个窗口允许源端在给定连接传送数据分段而不用等待目标端返回ACK,一句话描述:窗口的大小决定 ...

  2. TCP Window Full 和 TCP ZeroWindow

    文章目录 描述 参考资料 描述 项目现场遇到车在地图上丢失/跳点问题,通过日志发现是OBU给车发送阻塞导致(OBU给车发数据发不动),这里OBU 是TCP Server,车和平板APP是Client. ...

  3. linux tcp窗口大小设置,高性能Linux:TCP/IP内核参数调优之TCP窗口扩大因子(TCP Window Scaling)选项(理论篇)...

    TCP报文窗口字段介绍 在TCP报文头部,有一个16比特的窗口字段,用来表示接受方的缓冲区大小,发送方可以根据这个值的大小来调节发送的数据量,从而起到流控的目的. TCP的流量控制由连接的每一端通过声 ...

  4. ble之Transmit window offset and Transmit window size

  5. Fiori 里周期性检查window size大小的变化

    UI5框架里使用this.setInterval注册了一个每隔200毫秒(Core._I_INTERNAL)执行的job: 在Chrome里获得不同的log level: 在console里手动执行l ...

  6. ui5里周期性检查window size大小的变化

    Created by Jerry Wang, last modified on May 18, 2015 attachIntervalTimer oTimedTrigger sap.ui.core.I ...

  7. AssertionError: The input shape (7, 7) is smaller than the window size (12). Please set `pad_smal...

    我是在mmclassification训练自己的数据集中遇到的. 我继承的是s - transformer的base384.py 解决办法就是 window_size  修改成7 具体可以参考官方的A ...

  8. TCP性能和发送接收Buffer的关系

    本文希望解析清楚,当我们在代码中写下 socket.setSendBufferSize 和 sysctl 看到的rmem/wmem系统参数以及最终我们在TCP常常谈到的接收发送窗口的关系,以及他们怎样 ...

  9. 浅谈TCP的窗口字段

    该掸掸这里的灰尘了,写一篇关于TCP的文章吧.今天的主题是TCP的滑动窗口.在开始这个话题之前,我想先提几个关于TCP协议的常见误区. 误区1:TCP协议三次握手过程中后两个包都是[ACK]包. 解释 ...

最新文章

  1. 编译android不再需要jdk1.5
  2. Nodejs模块、自定义模块、CommonJs的概念和使用
  3. Win8消费者预览版下载地址 包含中文下载地址及中文手册
  4. 特定领域因果事件图谱构建项目
  5. sqlcheck约束表达式怎么写_creo 5.0 建模实例教程----乌比莫斯之环教程(表达式扫描特征)...
  6. 第二章 如何在VS2008里面编译CG
  7. THUSC2019去不了记
  8. EF CodeFirst类生成器
  9. windows server 2012无法安装NET.framework3.5解决方法
  10. SpringMVC中@RequestMapping参数设置
  11. asp.net园林绿化服务交易网站(三层架构)案例
  12. MySQL中临时表(TEMPORARY)
  13. 使用Java读写dbf文件【附源代码】
  14. 用手机当电脑摄像头的方法
  15. VMware Workstation 无法连接到虚拟机.....
  16. 读博与怠工(在北航硕博连读)——转载
  17. 消防中计算机基础知识,消防基础知识考试题
  18. 参考文献名称怎么复制_PDF格式的英文文献怎么翻译成中文?教你一招最简单快速的办法...
  19. 淘宝天猫店铺微信公众平台建设指南
  20. html 按钮吸底,CSS实现footer“吸底”效果

热门文章

  1. 84.LAMP的apache用户认证,域名跳转,日志文件
  2. Quartz教程五:SimpleTrigger
  3. redis学习篇(九)-----高级特性之事务处理
  4. flex4 权威指南 part01
  5. 交换机集群管理(锐捷)
  6. Delphi中对Jpeg格式文件的处理
  7. 读书:鲁迅的《故事新编》
  8. 问题四十八:怎么用ray tracing画superhyperboloid(超级双曲面)
  9. 物联网卡如何帮助农民提高收益
  10. pytorch实现attention_Self-Attention手动推导及实现