Threading make computer slow

P

PH

Hi guys;



I got a single processor computer, running an application that launches
2 threads.

Each of these threads listens for incoming connections in a specific
port, so there is a Loop . Until inside each of them.

When a packet is received the thread calls a method that process the
packet, and so on, this happens for every packet in any of those 2
ports.



THIS SI NOT THE ACTUAL CODE, BUT IS SOMETHING ALIKE



--------------------------



Dim Thread1 as new Thread (addressOff ProcessPacket)

Thread1.Start



Dim Thread2 as new Thread (addressOff ProcessPacket)

Thread2.Start





Private Sub ProcessPacket

Do

BeginAccept( WhateverProc)

Until bStop

End Sub





Private Sub WhateverProc

Process the packet

End Sub



--------------------------



Now, my problem is that in a period of time, lets say 30 seconds, I only
receive 4 packets (this is only when I test, in production will be a LOT
more, believe me ;-) )

What happens is that the processor's resources are almost gone, and the
computer reacts responsive less.

If this is happening with 4 packets, I don't what to even imagine what
will happen with 100.

Is there any way to easy the life of the processor even with more
traffic coming in?



Thanks
 
T

Tom

Have you tried putting an Application.DoEvents in your Do loop? It
would seem that would allow other messages/threads to be processed and
should reduce your CPU usage. Otherwise, you may have to redesign the
thread so that it processes on a timer - i.e. only runs once every 15
seconds or something.

Tom
 
P

Patrice

What if you don't use threading at all ? Once done, if it works fine it's
likey a problem with the multithreading part, else if it still perform badly
this is likely a problem with how the connection is managed...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top