LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer vs Master/Slave Data loss

Solved!
Go to solution

Hello Labview users,

I have been experimenting with P/C vs M/S lately in the context of data aquistion. Lots of posts have made it sound (Correct me if I'm wrong) that P/C is the correct architecture to if data preservation is desired, so that's what I've tried to implement.

In the producer loop, I've included 3 DAQ assitant VIs (2AO, 1 AI), one that actively generates data and is being enqueued. I have 3 other consumer loops, two of which are consumer loops 1) Writes data to TDMS 2) Outputs to a graph 3) Non producer: Event structure, monitors changes to UI.

When I run data aquisition, the file generated are consistently half i.e. aquire half the number of sample that  I have specified regardless of the sampling rate. I also have a weird graph being displayed (See attached image). 

 

However,

When I replace the architecture with a Master/Slave, this seems to solve the whole problem.

 

Question therefore is: has anyone come across such problems? Are there any downsides to sticking with M/S as opposed to P/C in terms of data loss?

Thanks

Download All
0 Kudos
Message 1 of 7
(3,749 Views)

Can you please elaborate more on what you have differently between your Producer/Consumer and Master/Slave code? Producer/Consumer is a subset of Master/Slave and so dominant these days that I don't hear the term Master/Slave used much anymore.

 

If you're losing data then there's something you must be doing wrong. Please include a Snippet of your code, or attach your VIs, so that we can better assist you.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 7
(3,723 Views)

From the picture you have attached, you only have one queue.

Do you have multiple loops that are dequeueing from the same queue? That is a no go!

You need to have a queue for every consumer that you have.

Message 3 of 7
(3,707 Views)

Didn't know you could do a snippet. Here goes. I believe that I am properly dequeueing 

0 Kudos
Message 4 of 7
(3,676 Views)
Solution
Accepted by johnji

@johnji wrote:

I believe that I am properly dequeueing 


You are not.  Once an item is dequeued, it is gone.  Since you have three loops dequeueing from the same queue, each loop will get ~1/3 of the data.  If all of the loops are to process everything, then you will want a different queue for each loop and have the producer write to each queue.  Alternatively, you could use an User Event.


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 5 of 7
(3,659 Views)

johnji wrote:

Question therefore is: has anyone come across such problems? Are there any downsides to sticking with M/S as opposed to P/C in terms of data loss?

Thanks


Back to the original question.

 

The main difference between Master/Slave and Producer/Consumer is that M/S using a Notifier while a P/C uses a queue.

 

A Notifier is a broadcast message, so everybody can get it.  However, you can miss a notification if your loop is slow.  The Notifier is lossy.  You overwrite a notification each time you write to the notifier.

 

A Queue is a lossless FIFO.  It is meant to only be read from 1 consumer.

 

So if you truely want no data loss, then you need to use a queue.  But since you are trying to have many loops dequeue the data, you really need a different queue for each consumer loop.


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 6 of 7
(3,651 Views)

crossrulz wrote:

So if you truely want no data loss, then you need to use a queue.  But since you are trying to have many loops dequeue the data, you really need a different queue for each consumer loop.


To expand on Cross' text: Queues are a Many-to-one relationship, Events are One-to-many. If you want to signal many loops you should use an Event driven producer/consumer, or use individual queues for the relationship reasons just stated.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 7
(3,611 Views)