当内部缓冲区填满时,TCP中会发生什么 [英] What happens in TCP when the internal buffer fills up

查看:122
本文介绍了当内部缓冲区填满时,TCP中会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我们有以下TCP套接字设置,其中客户端将任意数据发送到服务器.将以下内容视为伪代码.

Let's say we have the following TCP socket setup where client sends arbitary data to the server. Treat the following as a pseudocode.

def client():
    while True:
        data = source.get_data()
        client_socket.send(data)

服务器读取数据并使用它来做某事...

The server reads the data and uses it to do something...

def server():
    while True:
        data += socket.recv(4096)
        parsed_data = parse_data(data)  
        cpu_intensive_task(parsed_data)

让我们假设客户端发送数据的速度比服务器处理速度快得多.内部网络缓冲区可以填满吗?我认为答案是肯定的.

Let's assume that client will send the data much faster than the server can process. Can the internal network buffer fill up? I assume the answer is yes...

如果是,那么TCP协议是否指定在这种情况下会发生什么?这些离散的数据包是否像在运输过程中丢失并像其他丢失的包裹一样被重新传输一样对待?

If so, then does the TCP protocol specify what will happend in this scenario? Are these discared packets treated as if they were lost in transit and just re-transmitted like any other lost packages?

或者这些数据包真的丢失了吗?在TCP之上设计自己的通信协议时,我必须考虑这一点吗?

Or are these packets truly lost and this something I have to consider when desiging my own communication protocol on top of the TCP?

答案在不同的操作系统之间会有所不同吗?

Does the answer vary between operating systems?

作为记录,上面的系统应该具有某种拥塞控制机制,服务器可以使用该机制来告诉客户端它正处于高负载状态或再次处于空闲状态.但是,我很想知道默认情况下TCP在这种情况下的行为.

For a record, the system above should have some kind of congestion control mechanism, which server could use to tell the client that it's under heavy load or it's free again. However, I'm curious to know how the TCP by the default would behave in this scenario.

推荐答案

内部网络缓冲区可以填满吗?

Can the internal network buffer fill up?

有两个 内部缓冲区:发送缓冲区和接收缓冲区.两者都可以填满.

There are two internal buffers: the send buffer and the receive buffer. Both can fill up.

我认为答案是肯定的...

I assume the answer is yes...

是的

如果是,那么TCP协议是否指定在这种情况下会发生什么?

If so, then does the TCP protocol specify what will happen in this scenario?

是的

这些丢弃的数据包是

Are these discarded packets

没有丢弃的数据包.在这种情况下,TCP不会丢弃数据包.发送缓冲区填满时会发生什么情况取决于您是处于阻塞模式还是非阻塞模式,或者您是否正在使用异步API:

There are no discarded packets. TCP does not discard packets in this circumstance. What happens when the send buffer fills depends on whether you are in blocking or non-blocking mode, or whether you are using an asynchronous API:

  • 阻止模式:发送方阻止
  • 非阻止模式:发送方收到错误EAGAIN/EWOULDBLOCK
  • 异步:此操作将继续推迟.

将它们当作在运输途中丢失了,就像其他丢失的包裹一样重新传输了?

treated as if they were lost in transit and just re-transmitted like any other lost packages?

不.见上文.

这些数据包真的丢失了吗?

Or are these packets truly lost

不.见上文.

在基于TCP的协议上设计自己的通信协议时,我必须考虑这一点吗?

and this something I have to consider when desiging my own communication protocol on top of the TCP?

不.看上面.但是,在协议的实现中肯定要考虑各种条件.

No. See above. But the various conditions are certainly something you have to consider in your implementation of the protocol.

答案在不同的操作系统之间会有所不同吗?

Does the answer vary between operating systems?

否.

作为记录,上面的系统应该具有某种拥塞控制机制

For a record, the system above should have some kind of congestion control mechanism

TCP已经具有拥塞控制机制.

TCP already has a congestion control mechanism.

哪个服务器可以用来告诉客户端负载很重

which server could use to tell the client that it's under heavy load

如何?如果客户端没有阅读,服务器如何告知呢?

How? if the client isn't reading, how can the server tell it anything?

或再次免费.但是,我很想知道默认情况下TCP在这种情况下的行为.

or it's free again. However, I'm curious to know how the TCP by the default would behave in this scenario.

请参阅上文.

这篇关于当内部缓冲区填满时,TCP中会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆