我正在研究linux在linux上的性能。具体而言,确保框架本身内可用的工具可能存在何种类型的限制。
我一直在用50,000便士打这个盒子。到目前为止,大约有20,000个pps是UDPClient在丢包之前所能达到的。使用另一个工具(syslog-ng),数据包丢失率很低/很少见。
如果我希望处理超过50K的pps,UdpClient是否能够通过适当的调优来处理这个问题?
using (UdpClient udpListener = new UdpClient(_sysLogPort))
{
udpListener.Client.ReceiveBufferSize = _bufferSize;
while (!_cts.IsCancellationRequested)
{
try
{
UdpReceiveResult result = await udpListener.ReceiveAsync();
}
catch (Exception ex)
{
}
}
}发布于 2017-08-10 13:16:08
即使您的应用程序使用udpListener.ReceiveAsync();启动了一个新线程,它也会在尝试接收新数据包之前等待它的终止。因此,一次只有一个线程处理新接收的UDP数据包,以创建一个类型为UdpReceiveResult的对象。因此,它与single-threaded应用程序非常相似:您可以使用而不是来利用在多核系统上运行的机会。
您可能会得到更好的(显然取决于您的硬件),使用下面的方式编写程序。在本例中,有一个由5个线程组成的池,它们并行运行,同时创建多个UdpReceiveResult实例。即使数据包一次由内核处理,创建UdpReceiveResult实例的用户进程也是通过这种编程方式并行完成的。
// example of multithreaded UdpClient with .NET core on Linux
// works on Linux OpenSuSE LEAP 42.1 with .NET Command Line Tools (1.0.4)
// passed tests with "time nping --udp -p 5555 --rate 2000000 -c 52000 -H localhost > /dev/null"
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace hwapp {
class Program {
// listen to port 5555
UdpClient udpListener = new UdpClient(5555);
static void Main(string[] args) {
Program p = new Program();
// launch 5 threads
Task t0 = p.listen("thread 0");
Task t1 = p.listen("thread 1");
Task t2 = p.listen("thread 2");
Task t3 = p.listen("thread 3");
Task t4 = p.listen("thread 4");
t0.Wait(); t1.Wait(); t2.Wait(); t3.Wait(); t4.Wait();
}
public async Task listen(String s) {
Console.WriteLine("running " + s);
using (udpListener) {
udpListener.Client.ReceiveBufferSize = 2000;
int n = 0;
while (n < 10000) {
n = n + 1;
try {
UdpReceiveResult result = udpListener.Receive();
} catch (Exception ex) {}
}
}
}
}
}https://stackoverflow.com/questions/45578855
复制相似问题