LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wait Time for Loop and CPU usage....

I am using TCP to communcate between executables. I am going to open a connection at the onset and keep a connection open. The exe's will not be communicating constantly so I am going to continuoulsy be reading from the connection and when there is data I will process it, otherwise the timout value on the read will expire and i will ignore it.

 

 

Ideally I would want these reads to happen one after another so that there is no needless delay time added to the processing of the data. The TCP read VIs are ina  loop. I noticed that with no delay time the CPU gets pinned to 100% (as I would've imagined). But I also noticed that there isnt any noticelable difference in CPU usage when the wait time is at 1ms or 100ms.... With either 1ms or 100ms the cpu is just bobbing up and down at around 1-3%, same amount as if I am not running any code. I would've thought that there would be a difference between 1ms and 100ms, why is this? Is it because even 1ms is a very long time for a 3GHz processor, so going from 0 wait time to 1ms is a huge jump for the processor? If this is the case is there any reason why I shouldn't just use 1ms for a wait time because I want my code to be as efficient as possible when responding to TCP read and writes?

 

Thanks for the help

 

-Anthony 

0 Kudos
Message 1 of 4
(4,377 Views)

For fun, put a wait statement in there that has a zero wired to it.  You'll see that it is far less CPU usage than if you had no wait statement at all.

 

Even a wait statement with zero wait is able to yield time to the processor to handle other tasks rather than pinning the CPU had 100% doing nothing at all in an empty while loop.

0 Kudos
Message 2 of 4
(4,372 Views)

Ah yes, I guess a 0 input for the wait VI has a unique function. I should've been a bit more clear in my post, it is actually a event structure inside of a while loop.

 

Hmmmmm, but that might be exactly what I am looking for. So with the "Wait (ms)" VI if you wire a 0 it will yield to any other processes in queue to go to the processor, but if there none it will actually not wait at all?? Do you know how this VI works with 0 input?

Message 3 of 4
(4,349 Views)

Wiring a 0 to Wait releases the thread. period. a thread switch will occur.  If no other threads have any operations pending the thread will reaquire but a thread switch (with all overhead) does occur.


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 4
(4,337 Views)