文档章节

What is Delayed ACK and how can it be a bottleneck

robin-yao
 robin-yao
发布于 2015/11/14 17:32
字数 1350
阅读 124
收藏 0

Before explaining what Delayed ACK is, lets start by clarifying some concepts.TCP/IP is used to refer to two different things. On one side TCP/IP is a suite of protocols that rule the Internet containing protocols like HTTPTelnet,ICMP,SSH and many others. On the other side TCP/IP is also a pair of protocols themselves. TCP as a protocol in the transport layer, and IP as a protocol in the Internet Access Layer.
Both TCP and IP protocols where invented by the fathers of the Internet: Vint Cerf and Bob Kahn. Thanks fathers of the Internet!


TCP/IP, as a suite of protocols which includes the protocols TCP and IP, does not follow strictly the OSI model based in 7 layers. 

Instead a four layer (simpler) approach known as Internet model is followed (see below)


Image source: http://spectrum.ieee.org/computing/networks/osi-the-internet-that-wasnt

The four layers of the Internet model are: Network Access, Internet, Transport and Application. As the Internet model is simpler than the OSI model, one layer in the Internet model corresponds to several layers in the OSI model. This is true except for the layers Internet and Transport where both models are basically the same. 

TCP and IP are the rock stars protocols of the suite of protocols known asTCP/IP.

IP is a protocol in the Internet layer serving the transport layer.On the other sideTCP is one protocol in the transport layer. There is another famous protocol in the transport layer called UDP. The function of TCP or Transmission Control Protocol as per Wikipedia is 'to provide a reliable, ordered and error-checked delivery of a stream of octets (bytes) between programs running on computers connected to a local area network, intranet or the public Internet'.

UDP, in contrast with TCP, is a transport protocol with no guarantee of delivery, ordering, or duplicate protection. There are some scenarios where UDP is better than TCP (for example VoIP), but TCP is by far much more used. Lets focus onTCP protocol, as it is the relevant protocol for explaining Delayed ACK.

As TCP needs to guarantee the delivery of the segments, every segment being sent from the source (client) to the destination (server) needs to be acknowledged.

The structure of the TCP header is as follows:

There is a 32 bits (4 bytes) field in the TCP header that is known as thesequence number. There is also another 32 bits field for the ACK numberand 9 bits for flags. One of the flags is a bit for ACK that must be set to 1 for indicating that the segment transmitted contains an acknowledgment of one or more segments already received. How many segments are acknowledged will depend on the ACK number value. If the ACK number is the same that the sequence number of the last segment +1, then is acknowledging only one segment. If not, then it is acknowledging several.

How data is transmitted and acknowledged in TCP:

Lets imagine that a host A is sending a segment to a host B which contains 1000 bytes of data. Suppose that the initial sequence number of the segment is 10.

Once the host in destination receives the segment, it will take the sequence number (10) and will add 1000 (the number of bytes received) to that sequence number.

10+1000=1010

Then when host B wants to acknowledge the reception of that segment to A, it will send a segment back containing an ACK number of 1011 and the ACK flag bit turned on.

Please not that the ACK number is 1011 instead of 1010. 

This is basically saying:

Hey! I have received until byte 1010, please next time you communicate with me start with a segment whose sequence number is 1011. Apart from that, an ACKcan be pure if contains no data and is just for acknowledging one or more segments, or it can be not pure when apart from the ACK it contains data that is sent back from destination to source (this technique is know as piggybacking.

Sending a pure ACK is an opportunity lost; is the lost opportunity of sending anACK with data, instead of just a simple bit of information. In that sense it has an opportunity cost. Why? Because of the protocol overhead.

Remember that sending 1 bit of information does not only require 1 bit of information transmitted over the network, but that bit of information plus size of the headers.
The headers in TCP/IP are normally 40 bytes, so for sending 1 bit of payload, we are using 41 bytes!.

Bad thing right? Yes, too much overhead!

Delayed ACK to the rescue

Delayed ACK was invented to reduce the number of ACKs required to acknowledge the segments, so protocol overhead is reduced.
The specification can be found here: https://tools.ietf.org/html/rfc1122

Basically Delayed ACK is the destination retaining the ACK segment a period of time (200 ms in Microsoft Windows by default), expecting one of two things to happen:

1) That a new segment will arrive that will also require acknowledge, so we can ACK two segments in one pure ACK instead of in two separate ACKs; avoiding that way to transmit over the network 41 extra bytes. 

2) That, perhaps, before the ACK timer expires, the destination will need to send some data back to the source in which we can include the ACK bit and the rightACK sequence number to acknowledge the segment (piggybacking).

So delayed ACK is basically a bet.


Is the bet of destination saying "I bet 200 ms (or the value of the delayed ACK timer) that a new packet will arrive before the delayed ACK timer expires, or that we will need to send our own data back to the sender before 200 ms (in which we can include an ACK bit flag enabled). If I win, I save 41 bytes of the extra ACK I am avoiding. If I loose I lost a maximum of 200 ms

To illustrate the behaviour I have coded in a pseudo language derived from C a"Delayed ACK Algorithm"

Obviously it is not real implementation, is just an example to clarify things.

segment_received=0;
ack_delayed_timer=200;
timer=0;

while(connection_open)
{

while(timer<ack_delayed_timer)

if(there_is_a_segment_from_source())
segment_received++;

// If is the first segment, but there is data to be send back to source
// then we can add the ACK flag in that segment - piggybacking

if(segment_received==1 && is_possible_piggy_back())
{
piggy_back(sequence_number_of_the_last_segment+1); // ACK within the data
segment_received=0;
timer=0;
break;
}


// if 2 consecutive segments are received, we send a pure ACK

if(segment_received==2)
{
send_pure_ack(sequence_number_of_the_last_segment+1);
segment_received=0;
timer=0;
break;
}


sleep(1ms); 
timer++;

} //end while timer<ack_delayed_timer

// We could be here because the timer has expired without receiving a second segment so send a pure ACK, or because a break (ACK already sent)

if(timer==200)
{
send_pure_ack(sequence_number_of_the_last_segment+1);
segment_received=0;
timer=0;
}

} // end while connection open

Practical Example:

Segment 1 arrives to destination. Destination starts the ACK timer of 200 ms. Before the timer expires…

Segment 2 arrives. Destination sends a pure ACK as this is the second segment pending ACK in the queue.

Segment 3 arrives. Destination starts the ACK timer of 200 ms. Before the timer expires…
A packet with data needs to be send from destination to source. A non pure ACK(piggy-backed) is encapsulated with the answer and send back from B to A .

Segment 4 arrives. Destination starts the ACK timer of 200 ms. Timer expires…Destination sends a pure ACK.

There are, however some scenarios where Delayed ACK harms mores than heals.

Imagine that the source does not send more data if segments already transmitted are not acknowledged. In this case we are delaying each transmission of a TCPsegment 200 ms (or the Delayed ACK timer value).

One particular bad scenario is when Nagle´s Algorithm is in place together withDelayed ACK.

Fortunately in those scenarios Delayed ACK can be disabled or tuned.


本文转载自:https://www.linkedin.com/pulse/20141113153643-13386347-what-is-delayed-ack-and-how-can-it-be-a-bo...

robin-yao
粉丝 167
博文 54
码字总数 61436
作品 0
杭州
私信 提问
简单的 HTTP 调用,为什么时延这么大?

1. 背景 最近项目测试遇到个奇怪的现象,在测试环境通过 Apache HttpClient 调用后端的 HTTP 服务,平均耗时居然接近 39.2ms。可能你乍一看觉得这不是很正常吗,有什么好奇怪的?其实不然,我...

涤生_YinQi
07/14
0
0
TCP之Nagle算法

Nagle算法 Nagle算法是为了提高带宽利用率而设计的算法,该算法主要用于避免过多小分节报文在网络中传输。比如一个20字节的TCP首部+20字节的IP首部+1个字节的数据组成的TCP数据报,有效传输通...

金桔柠檬茶
2016/10/17
100
0
TCP Nagle算法&&延迟确认机制

TCP Nagle算法&&延迟确认机制 TCP Nagle算法 http://baike.baidu.com/view/2468335.htm 百度百科:TCP/IP协议中,无论发送多少数据,总是要在数据前面加上协议头,同时,对方接收到数据,也需...

秋风醉了
2015/07/30
3.4K
0
网络40ms延迟问题

问题背景: 我 们一个企业用户准备把线上业务从共享的mysql服务迁移到独立型mysql rds上。企业用户那边先搞了一个test版本到我们rds环境,发现网站响应时间从3s变为40s。由于是php应用,故我...

leejia1989
2016/03/30
0
0
神秘的40毫秒延迟与 TCP_NODELAY

最近的业余时间几乎全部献给 breeze 这个多年前挖 下的大坑—— 一个异步 HTTP Server。努力没有白费,项目已经逐渐成型了, 基本的框架已经有了,一个静态 文件模块也已经实现了。 写 HTTP...

天天顺利
2015/10/08
83
0

没有更多内容

加载失败,请刷新页面

加载更多

idea 打开一个新的项目,maven都需要重新配置,解决方案

需要有个默认全局配置 File->Other Settings -> Default Settings 将Maven home directory目录修改成我们自定安装Maven的目录...

观海562
36分钟前
4
0
链表中环的入口节点

给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null。 思路: public ListNode EntryNodeOfLoop(ListNode pHead) { if (pHead == null || pHead.next == null) ...

Garphy
57分钟前
5
0
Spring5 源码分析-容器刷新-invokeBeanFactoryPostProcessors()方法

上一篇:Spring5 源码分析-容器刷新-prepareBeanFactory()方法 该方法主要完成以下功能: 1.实例化ConfigurationClassPostProcessor,并调用ConfigurationClassPostProcessor.postProcessBe...

特拉仔
57分钟前
7
0
为什么MySQL用B+树做索引

索引这个词,相信大多数人已经相当熟悉了,很多人都知道MySQL的索引主要以B+树为主,但是要问到为什么用B+树,恐怕很少有人能把前因后果讲述的很完整。本文就来从头到尾介绍下数据库的索引。...

小致Daddy
今天
8
0
网站前台的三级联动数据封装

我在进行项目时候遇到了一个进行数据封装的一个功能,进行数据的封装的功能也挺复杂,来回试了好几十种方法.最后使用的是这种方法. 使用一个pojo进行封装两个数据,一个是list一个是实体类. 具体...

小天丶羽
今天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部