-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use WinDivertRecvEx #304
Use WinDivertRecvEx #304
Conversation
@trudyhood I believe you have an application/setup to test WinDivert performance since you reported #273, could you check this PR? |
Codecov Report
@@ Coverage Diff @@
## master #304 +/- ##
==========================================
+ Coverage 79.86% 80.12% +0.26%
==========================================
Files 35 35
Lines 2155 2194 +39
Branches 241 244 +3
==========================================
+ Hits 1721 1758 +37
- Misses 339 340 +1
- Partials 95 96 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@kayoub5 No Filter
Old SharpPcap
New SharpPcap with batch
Original WinDivert Batch 1 : passthru.exe true 1 1
Original WinDivert Batch 10 : passthru.exe true 1 10Speedtest by Ookla
I used the following code: using PacketDotNet;
using SharpPcap.WinDivert;
using System;
using System.Threading;
namespace SimpleFilter
{
class Program
{
static readonly WinDivertDevice WinDivert = new();
private static long _length;
private static long _lastLength;
static void Main()
{
WinDivert.Layer = WinDivertLayer.Network;
WinDivert.Filter = "ip";
WinDivert.Flags = 0;
WinDivert.Open(new SharpPcap.DeviceConfiguration());
WinDivert.OnPacketArrival += WinDivert_OnPacketArrival;
Console.WriteLine("Working...");
WinDivert.StartCapture();
Thread.Sleep(-1);
}
private static void WinDivert_OnPacketArrival(object sender, SharpPcap.PacketCapture e)
{
var rawPacket = e.GetPacket();
var packet = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
var lastCaptureHeader = (WinDivertHeader)e.Header;
var ipPacket = packet.Extract<IPv4Packet>();
WinDivert.SendPacket(ipPacket.Bytes, lastCaptureHeader);
_length += packet.TotalPacketLength;
if (_length > _lastLength + 1000000)
{
_lastLength = _length;
Console.WriteLine(_lastLength);
}
}
}
} |
@trudyhood I only implemented WinDivertRecvEx, sending is still being done packet per packet |
@kayoub5 I wish SharpPcap.PacketCapture contains an array of packets instead of a single packet but I think it would be big change! |
Ya, I saw your message after sending my own. |
@trudyhood could you profile your application and upload the results, my ISP is not fast enough to test 200Mbps 😞 See https://docs.microsoft.com/en-us/visualstudio/profiling/cpu-usage?view=vs-2019 Instrumentation, CPU usage and .NET Object Allocation Tracking are the interesting reports in this case |
@kayoub5 My ISP is not that fast; I compiled it on my machine and ran it on an Amazon EC2 server with 1Gbit speed. Unfortunately, it just has 1GB of memory which is not enough to install visual studio. |
Just checked with profiler with 40Mbps traffic, most of the CPU time goes to either So the good news is that this PR introduce no regression performance, and should allow faster reception of packets. The not so good news is that we need some kind of API for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This improves performance when capturing using windivert? I saw the messages on the ticket but didn't read them in depth to confirm this was the case.
Yes. |
I believe it is much more to be done, the improvement is not noticeable yet. |
Pending reply on basil00/WinDivert#282 to finish implementation
Partially resolves #273