dotpcap / sharppcap

Official repository - Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets
1.31k stars 267 forks source link

Improving WinDivert perfomance by using BatchMode offered in WinDivertRecvEx #273

Open trudyhood opened 3 years ago

trudyhood commented 3 years ago

I have found out that WinDivert performance can be increased significantly by using batch mode offered in WinDivertRecvEx. Can you implement WinDivertDevice with BatchMode using WinDivertRecvEx instead WinDivertRecv? The performance is near 3x on high bandwidth and CPU utilization looks lower.

Please consider WinDivertSendEx too.

trudyhood commented 3 years ago

Sorry, no any comment about this?

chmorgan commented 3 years ago

It’s a good idea. Let me look at how we might support that feature once I’ve wrapped up some changes I have pending to clean up the API.

On Sun, May 2, 2021 at 7:31 PM trudyhood @.***> wrote:

Sorry, no any comment about this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/chmorgan/sharppcap/issues/273#issuecomment-830925927, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJH4AEXIIPEBKHNVPN5TZDTLXODTANCNFSM43ASH5UA .

trudyhood commented 3 years ago

Very good, really waiting for that. Thank you

chmorgan commented 3 years ago

Alright, took a look at the recv api. I'm not sure if/when I'd get to the changes but if this was implemented I think we'd want to do something like:

and of course we'd want to add a test to test the new method.

trudyhood commented 3 years ago

I hope you make the changes. I should say congratulation for updating to version 6. It looks version 6 is 30% faster. Using batch mode with WinDivert increases the speed by more than 300%! You can check the performance difference with windivert passthru.exe on a gigabit network.

passthru.exe [filter] [num-threads] [batch-size] passthru.exe true 1 10

kayoub5 commented 3 years ago

Keeping this open until WinDivertSendEx is supported as well

verdie-g commented 2 weeks ago

DeviceModes.MaxResponsiveness is currently unused for WinDivertDevice.

Would it make sense to read X packets in the first call to GetNextPacket then returns the already loaded packets on the next calls. But if DeviceModes.MaxResponsiveness is set, then the batch size becomes 1.

kayoub5 commented 1 week ago

That generally have little benefit, the main point of batch processing for a network processing library is being able to process the batch elements in parallel at the application side.