取消
显示结果 
搜索替代 
您的意思是: 

How to set the timeout of a Notifier in a consumer loop if intention is to run no faster than the producer loop

已解决!
转到解答

If I have a producer loop sending a notification every X ms, what value should I wire to the consumer's Wait on Notification timeout to ensure the consumer loop runs no faster than the producer?

 

For example, in the snippet below, I would set timeout of the consumer loop equal to the wait of the producer loop, however, when I do this, I see a loop rate of ~0 s. 

Why does this happen?

To ensure the consumer loop runs no faster than the producer, what should I wire to the timeout with respect to the wait of the producer loop?

 

ChuckVersusTheVI_0-1714067402795.png

 

 

"Computer Emergency"
0 项奖励
1 条消息(共 9 条)
1,681 次查看
解答
已被主题作者 ChuckVersusTheVI 接受

Leave the timeout input unwired and it will default to waiting "forever".  If you really need a timeout, you just need something that is (much) larger than the producer loop rate.



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 项奖励
2 条消息(共 9 条)
1,655 次查看

Understood. That is congruent with what I found by increasing the timeout past the producer loop rate.

I am still confused why having the timeout value the same or very similar to the producer loop rate would cause the consumer to become a 'greedy' loop and run as fast as possible?

"Computer Emergency"
0 项奖励
3 条消息(共 9 条)
1,653 次查看

I think I see what is happening now.  I think you are seeing a combination of a timeout and then immediately getting the Notification, which results in a loop rate of 0ms.



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
4 条消息(共 9 条)
1,643 次查看

I don't understand why the 'Wait on Notification' VI would behave that way.

Even if it timed out then immediately received a notification, it should still have to wait some amount until the next notification is received, not immediately get a new value over and over again, since the producer isn't sending new values that fast?

 

I modified the code to calculate the average loop rate over the current number of iterations, and I get a value that is about half of the specified timeout:

ChuckVersusTheVI_0-1714077604671.png

 

This is interesting and still would like to know exactly how the aforementioned combination creates the 0ms loop rate, but as said above, I get the desired functionality by setting the consumer timeout to higher than the producer rate. 

"Computer Emergency"
0 项奖励
5 条消息(共 9 条)
1,620 次查看

It's not that it becomes a greedy loop.  It's because your timestamp is calculating immediately when the iteration starts and not when the notification is being received.  One iteration will be really fast and the next iteration will be delayed while it waits for the message to be received.

 

I duplicated your code and when I run it, the consumer loop rate flashes.  I can see another larger value appear but it changes quickly.  It appears like your consumer is running really fast because you only see the 0.01ms value on the screen but it's because your timestamps are calculated wrong. 

aputman_0-1714080294426.png

 

aputman
6 条消息(共 9 条)
1,604 次查看

True, that is the behavior I expect, and so should be getting an alternating loop rate between 0 (really fast) and something greater than 0 (while it waits for the next notification), but instead what I'm seeing is a constant loop rate of 0ms when using the timestamp (Get Date/Time in Seconds) to calculate loop rate.

"Computer Emergency"
0 项奖励
7 条消息(共 9 条)
1,587 次查看

Wire the consumer loop rate to a waveform chart to see that you receive two values in quick succession. Or use a history probe.

8 条消息(共 9 条)
1,504 次查看

Ah good point, a waveform chart does show the expected behavior. Looks like I tricked myself by assuming the numeric indicator would catch that behavior. Thanks

"Computer Emergency"
0 项奖励
9 条消息(共 9 条)
1,502 次查看