TCP缓冲区在进程内存的地址空间中吗? [英] Is TCP Buffer In Address Space Of Process Memory?

查看:475
本文介绍了TCP缓冲区在进程内存的地址空间中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我增加TCP缓冲区的大小,以便更快地处理消息. 我的问题是,无论我为TCP消息使用了什么缓冲区(ByteBuffer,DirectByteBuffer等),每当CPU接收到来自诸如NIC的中断时,为了处理网络请求以读取套接字数据,OS都会在地址空间之外维护内存中的任何缓冲区吗?请求进程(例如正在侦听该套接字的进程)

I am told to increase TCP buffer size in order to process messages faster. My Question is, no matter what buffer i am using for TCP message(ByteBuffer, DirectByteBuffer etc), whenever CPU receives interrupt from say NIC, to handle network request to read the socket data, does OS maintain any buffer in memory outside Address Space of requesting process(i.g. the process which is listening on that socket)

无论CPU以何种方式接收网络数据,都将始终仅将其写入进程地址空间的缓冲区中,并且不保留地址空间之外的缓冲区(包括netstat命令的"Recv-Q"和"Send-Q")进行这种交流吗?

whatever way CPU receives network data, it will always be written in a buffer of process address space only and no buffer(including 'Recv-Q' and 'Send-Q' of netstat command) outside of the address space is maintained for this communication?

推荐答案

Linux网络堆栈接收数据的过程有点复杂.我写了综合指南Linux网络堆栈,它解释了从设备驱动程序到用户界面程序的套接字接收队列,您需要了解的一切.

The process by which the Linux network stack receives data is a bit complicated. I wrote a comprehensive guide to the Linux network stack that explains everything you need to know starting from the device driver up to a userland program's socket receive queue.

在内核中维护缓冲区的地方很多:

There are many places buffers are maintained in the kernel:

  1. 数据包到达后由NIC写入的DMA环.
  2. 对DMA环上的数据包的引用用于处理数据包.
  3. 最终,如果接收队列尚未满,则将数据包数据添加到进程的接收队列中.
  4. 从套接字读取将从进程的接收队列中提取数据包.
  5. 如果发生数据包嗅探,则会复制数据包数据并将其发送到由数据包嗅探代码添加的任何过滤器.

上面链接的博客文章中描述了如何移动,计算和删除数据的完整过程(需要时).

The full process of how data is moved, accounted for, and dropped (when required) is described in the blog post linked above.

现在,如果您想更快地处理消息,我想您的意思是想减少数据包处理的延迟,对吗?如果是这样,您应该考虑使用

Now, if you want to process messages faster, I assume you mean you want to reduce your packet processing latency, correct? If so, you should consider using SO_BUSYPOLL which can help reduce packet processing latency.

增加接收缓冲区只会增加可以排队进入用户区套接字的数据包数量.为了提高数据包处理能力,您需要仔细监视和调整网络堆栈的每个组件.您可能需要使用RPS之类的东西来增加处理数据包的CPU数量.

Increasing the receive buffer just increases the number of packets that can be queued for a userland socket. To increasing packet processing power, you need to carefully monitor and tune each component of the network stack. You may need to use something like RPS to increase the number of CPUs processing packets.

您还将希望监视网络堆栈的每个组件,以确保可用的缓冲区和CPU处理能力足以处理您的数据包工作量.

You will also want to monitor each component of your network stack to ensure that available buffers and CPU processing power is sufficient to handle your packet workload.

这篇关于TCP缓冲区在进程内存的地址空间中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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