This project is read-only.

Performance issues

Mar 19, 2012 at 8:07 PM

First of all I have to mention how great this wrapper is. secondly, I am wondering if opening a device and listening to it has to be so costly

here's part of my code:

public void incoming()
{
//the actual operation
PacketDevice selecteddevice = alldevices[deviceindex];
//open the device
using (PacketCommunicator communicator = selecteddevice.Open(65536, PacketDeviceOpenAttributes.None, -1)) // read timeout
{
using (BerkeleyPacketFilter filter = communicator.CreateFilter(infilter))
{
// Set the filter
communicator.SetFilter(filter);
}
this.status.Invoke(new MethodInvoker(() => this.status.Text = "listening on " + selecteddevice.Description + "......."));
while (true)
{
PacketCommunicatorReceiveResult result = communicator.ReceivePackets(0, incomingpackethandler);
}
}
}

public void outgoing()
{
//the actual operation
PacketDevice selecteddevice = alldevices[deviceindex];
//open the socket
using (PacketCommunicator communicator = selecteddevice.Open(65536, PacketDeviceOpenAttributes.None, 1)) // read timeout
{
using (BerkeleyPacketFilter filter = communicator.CreateFilter(outfilter))
{
// Set the filter
communicator.SetFilter(filter);
}
this.status.Invoke(new MethodInvoker(() => this.status.Text = "listening on " + selecteddevice.Description + "......."));
while (true)
{
PacketCommunicatorReceiveResult result = communicator.ReceivePackets(0, outgoingpackethandler);
}
}
}

Regardless of the packet function(even if it's empty) CPU utilization is always 40-50% no matter what, while the wireshark maxes at 10% or so, I understand that this wrapper would incur some additional overhead in terms of processing, but I'm wondering if it is possible to improve the performance, here's my start button:

if (deviceindex == 777)
MessageBox.Show("please select a device to monitor", "error");
else
{
timeelapsed.Start();
benchmarking.Enabled = true;
Thread starter = new Thread(incoming);
starter.IsBackground = true;
starter.Start();
Thread starter2 = new Thread(outgoing);
starter2.IsBackground = true;
starter2.Start();
connections.Enabled = true;
}

I've spawned 2 threads executing the outgoing function which filters all but outgoing data and the incoming function which does the opposite(for now).

Any help would be appreciated.

Coordinator
Mar 20, 2012 at 8:03 PM

Hi,

 

Have you tried running profiling of your application to see where is the bottleneck is?

Try running a single PacketCommunicator with the same filter you're using in Wireshark to compare the two, I think it makes sense that if you have 3 communicators and wireshark uses 1 you'll get 3 times more CPU consumption.

Why do you use 0 for the count in ReceivePackets() ? You can replace the infinite loop you have with ReceivePackets(-1, handler).

Also, check what is the result returned from ReceivePackets().

 

Let me know if this helps,

 

Boaz.

Mar 22, 2012 at 3:09 AM

I've cancelled one of te executing threads(leaving only 1 communicator open) still the exact same performance, i tried executing a blank function on the packets still the same performance, i replaced the count with -1 and the performance was exactly the same and i suffered some clashes in my critical section of hte program

ill start seperately benchmarking different parts of the communicator part and check where the bottle neck is

thanks for ur help , i will inform you as soon as i figure out anything

Coordinator
Mar 23, 2012 at 10:46 AM

If you replace the count with -1, you can remove the infinite loop.

If the call is not blocking, please check what is the return value.

 

I think running profiling could be very beneficial.

Mar 24, 2012 at 1:43 PM
Edited Mar 24, 2012 at 2:17 PM

I followed your advice and merged the incoming function with the outgoing function,  the CPU utilization at 0-12% !!!!!!(at both -1 and 0)

i think opening the device twice at the same time has a severe performance impact, Brickner I cannot thank you enough,  your help is greatly appreciated.

I will start recoding my entire application(as i have to seperate incoming data from outgoing data)