如何加快数据包的处理速度
本文关键字:处理速度 数据包 何加快 | 更新日期: 2023-09-27 17:51:10
我正在使用pcap.net
库在c# .net中开发一个呼叫记录应用程序。对于抓包,我使用的是Wireshark的Dumpcap.exe
。数据包文件在5秒内创建。要读取每个包文件,我所做的是
OfflinePacketDevice selectedDevice = new OfflinePacketDevice(filename);
using (PacketCommunicator communicator =
selectedDevice.Open(65536, // portion of the packet to capture
// 65536 guarantees that the whole packet will be captured on all the link layers
PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
0)) // read timeout
{
communicator.ReceivePackets(0, DispatcherHandler);
在DispatcherHandler方法中,我正在处理每个数据包。DispatcherHandler调用每个文件耗时0秒。
我在处理RTP数据包时得到延迟,数据包在相同的方法..
为了识别rtp数据包,我使用有序字典,键为ipadrress+portnumber
。所以我需要在每个rtp包到来时检查这个键是否存在于字典中。这个任务在处理每个转储文件时变得越来越慢。
if (objPortIPDict.Contains(ip.Source.ToString().Replace(".", "") + port))
{
// here i write the rtp payload to a file
}
我读了一些奇怪的东西:
1)为什么在Dictionary中使用Contains
?
objPortIPDict.Contains(ip.Source.ToString().Replace(".", "") + port)
如果objPortIPDict
是一个字典,使用ContainsKey
2)由first派生。如果这是一个Dictionary,它的containskey具有O(1)执行时间,因此不会受到Dictionary本身数据量的影响。
是的,它可能会受到影响,如果数据量变得如此大,整个应用程序变得更慢,但是对于当前应用程序状态域而言,拾取时间将始终保持不变。