multithreading - 在 Linux 中使用多队列 NIC

标签 multithreading networking network-programming multiprocessing packet-capture

我读过很多关于接收端扩展(RSS)、接收数据包引导(RPS)和类似技术的内容,但我不知道如何在我的程序中实际使用这些技术,即对传入的数据进行分区不同线程/进程之间的数据包。

我确实了解 PF_RING,但我想 Linux 内核本身一定有一些基础支持。毕竟,Interl 在其网站上夸耀其 RSS 技术,并声称支持 Linux。此外,RPS 超出了 PF_RING 的范围。我不愿意使用 PF_RING 的另一个原因是他们已经修补了网络驱动程序,而其中一些修补的驱动程序似乎已经过时了。

我已经在 google 上广泛搜索了该主题,但我发现的最好的内容是关于启用 RSS 或 RPS 支持,而不是如何以编程方式使用它们。

最佳答案

内核 3.19 引入了 SO_INCOMING_CPU 套接字选项。这样,该进程就可以确定数据包最初传送到哪个 CPU。

Alternative to RPS/RFS is to use hardware support for multi queue.

Then split a set of million of sockets into worker threads, each one using epoll() to manage events on its own socket pool.

Ideally, we want one thread per RX/TX queue/cpu, but we have no way to know after accept() or connect() on which queue/cpu a socket is managed.

We normally use one cpu per RX queue (IRQ smp_affinity being properly set), so remembering on socket structure which cpu delivered last packet is enough to solve the problem.

After accept(), connect(), or even file descriptor passing around processes, applications can use :

int cpu; socklen_t len = sizeof(cpu);

getsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU, &cpu, &len);

And use this information to put the socket into the right silo for optimal performance, as all networking stack should run on the appropriate cpu, without need to send IPI (RPS/RFS).

[https://patchwork.ozlabs.org/patch/408257/][1]

关于multithreading - 在 Linux 中使用多队列 NIC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10565468/

相关文章:

c++ - UB 具有不同类型的结构铸件?

ios - 在 ios 上跳跟踪 ttl reciveform

c++ - 使用异步调用与在线程中使用同步调用相同吗?

C# 字典索引超出带锁的数组范围

Java池连接优化

java.net.SocketException : Connection reset

c++ - Socket select() 第二次阻塞

java - 使用Java优化网络速度

network-programming - 是什么导致udp接收延迟?

c# - C#线程和属性第二部分