LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is a Wait timer needed in a consumer loop?

Solved!
Go to solution

I have a leak test engine and servo engine that is a consumer loop being called via "Start Asynchronous Call" multiple times for each device.  A contractor that I am working with said I need to add a wait timer since the dequeue will tie up the processor.  Is this true?

 

I kind of makes sense that the dequeue is waiting to process anything immediately, but I thought the timeout would release the loop just like a wait timer set to zero.  He says it does not since it is still waiting to dequeue something.  What does the experts think about this?

 

 

Timer.png

0 Kudos
Message 1 of 17
(3,262 Views)

No wait needed.  The Dequeue will time your loop.  Quickly based on your example, that timeout for the Dequeue isn't even needed.

 

EDIT:  Some additional notes after rereading the original post.  The Dequeue will "sleep" while waiting for data to come down the queue.  So not processor will be used.  And if you have a not in your queue, you really want that consumer to run as fast as it can anyways to try to play catchup.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 17
(3,253 Views)
In the rare case you generate the queue so fast it's always working it'd be a good idea, but then the question is if a queue is the best choice to begin with.
Usually a queue works on single or a few elements and then wait, in which case it isn't necessary.
/Y
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 17
(3,250 Views)

Sorry, I took the example to try to show how I was using it, this is part of my real code.  When I time out I read the current status and the queue is used to process commands. 

 

queue 2.png

0 Kudos
Message 4 of 17
(3,244 Views)

I think he was saying something about releasing a processor thread to allow something else a chance to run.  I don't remember exactly how he said it, but it sounded like it could be true at the time.  I have another application that could be running up to 50 engines in the background, so I would like to know more about the efficiency of the dequeue.

 

Edit:  He did say he was running on a virtual machine that only used 1 core of the processor and the code we were working on was running slow.  He put the wait timer in and it worked fine for him.  

0 Kudos
Message 5 of 17
(3,238 Views)

Well, even then, the CPU will get released a little bit due to the communications happening.

 

Yeah, things are going to get slowed down with just 1 core.  I really hope your systems are not going to be running single core.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 17
(3,232 Views)

So the dequeue will normally hold on to the CPU?  Is this similar to a empty loop without a wait timer?  Not much processing, but taking cpu resources?

 

The machines are running on new dedicated Core i7's, so I'm not worried about this project.  Just wanting to better understand this and looking into the future application that might run 50 engines in the background.

0 Kudos
Message 7 of 17
(3,216 Views)
Solution
Accepted by topic author nonecure

@nonecure wrote:

So the dequeue will normally hold on to the CPU?  Is this similar to a empty loop without a wait timer?  Not much processing, but taking cpu resources?


No.  If there is nothing in the queue, the Dequeue Element causes a "sleep".  This is similar to your Event Structure while waiting for events.  They use no CPU while waiting for a message.

 

Now if you have a lot of things in your queue, then your loop could be running as fast as possible to play catch up.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 17
(3,212 Views)

That is what I always thought, but why would he see a big improvement on his 1 core machine when adding the wait 0ms?  We have 7 engines (dequeue loops) running on this machine.

0 Kudos
Message 9 of 17
(3,207 Views)

I guess I read this incorrectly.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 17
(3,199 Views)