4

I'm using Windows Server 2008, and my program is in C++. I'm using WinSock2 and sendto() in a while(true) loop to send my packets.

Code like so:

while(true)
{
    if(c == snd->max)
        c = snd->min;

    dest.sin_addr.S_un.S_addr = hosts[c];
    iphead->destaddr = hosts[c];

    sendto(s, castpacket, pktsz, 0, castdest, szsad);

    ++c;
}

I need to send as much data to as many IPs in my hosts std::vector as possible, as quickly as possible.

I'm currently running on an i7 930 server, and I can only achieve 350Mbps or so.

I currently split my program into 4 threads, all running the while loop with different servers assigned to each thread. Adding more threads or running more copies of the program results in lower throughput.

I have another program running listening for replies from the servers. I get the servers from a master list and add them to my array. The problem at the moment is that it takes too long to go through all of them, and I want to check them regularly.

How exactly can I optimize my program/loop/sending here?

4

2 回答 2

2

我建议迁移到异步 I/O 以加快速度。一次发送一个的主要问题是,当 TCP 堆栈正在处理当前数据包时,您无法将下一个数据包排队。

或者,您可以采用线程池方法:触发一定数量的工作线程,每个工作线程从 FIFO 中提取一个客户端并将数据发送到客户端。当一个线程处理完它的客户端后,它会将客户端放回 FIFO 中并选择一个新的。您可以通过调整工作线程的数量来填充管道 - 但不能淹没它。

于 2011-09-04T17:46:01.357 回答
2

看看 WinSock 的Registered I/O Extensions (RIO) API:

RIO API 是 Windows Sockets (Winsock) 的新扩展,为您提供了减少网络延迟、提高消息速率和提高响应时间可预测性的机会,适用于需要非常高性能、非常高的消息速率和可预测性的应用程序。RIO API 扩展允许处理大量小消息的应用程序实现更高的每秒 I/O 操作 (IOPS),同时减少抖动和延迟。具有高消息速率和低延迟要求的服务器负载从 RIO API 扩展中获益最多,包括金融服务交易和高速市场数据接收和传播的应用程序。此外,当您在单个物理计算机上部署多个 Hyper-V 虚拟机 (VM) 时,RIO API 扩展提供高 IOPS。

RIO 使发送和接收操作能够使用请求和完成队列使用预先注册的缓冲区执行。发送和接收操作排队到与 Winsock 套接字关联的请求队列。完成的 I/O 操作被插入到完成队列中,许多不同的套接字可以与同一个完成队列相关联。完成队列也可以分为发送完成和接收完成。完成操作,例如轮询,可以完全在用户模式下执行,无需进行系统调用。

注册缓冲区的使用简化了网络相关处理,减少了抖动,此外还使应用程序开发人员可以指定协议栈使用的网络缓冲区的 NUMA 节点亲和性——进一步提高整体性能,并减少延迟和抖动特性。

RIO API 扩展支持传输控制协议 (TCP)、用户数据报协议 (UDP)多播 UDP,以及 IPv4 和 IPv6。

如果您想实现以下任何一项,您可以使用 RIO API 扩展:

  • 扩展您的服务器以最小化每条消息的 CPU 使用率

  • 将网络堆栈的延迟贡献和抖动降至最低

  • 处理非常高速率的多播或 UDP 流量

使用 RIO API 扩展具有以下额外好处:

  • RIO 适用于所有版本的 Windows Server 2012。

  • RIO 与普通网络适配器兼容,不需要特殊的网络适配器或 RDMA。

  • RIO 与现有的 Windows 网络功能完全兼容,包括 RSS、RSC、网络接口卡组合和静态卸载。

  • 在 Windows Server 2012 中部署 Hyper-V 时,RIO 与虚拟化一起使用。

  • RIO 套接字使用标准的 Windows 网络堆栈和标准的 TCP/IP 和 UDP 协议。

于 2020-10-14T23:03:52.187 回答