LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the Fastest producer consumer method. Queue, RT-FIFO, Event

Solved!
Go to solution

Hi all,

 

Another curly question for the pro's:

 

I have recently inherited some labview code that uses RT-FIFO for the transfer mechanism in the producer consumer architecture.

The code was first written 3-4 years ago and is presently in LV8.6. It is possible that the reasons for the architectural decision no longer exists.

 

I am skilled using a queued producer consumer architecure,

I understand the RT-FIFO Architecture.

I have begun using a user Event Based architecture.

(I have attached samples of each)

I also see the existance of a priority Queue

 

Each method has it's own capabilities and deficiencies, That aside, does anyone know the relative performance of each method.

(Assuming single process)

 

I would expect RT-FIFO to be fastest, it appears to be a low feature version of a standard queue.

 

What is the perfornace hit for using a more coding freindly Queue

The RT-FIFO description speaks of commications between time critical and lower priority threads.

Until today, I believed that Queues had the same capability.

 

Producer - Consumer.png

 

 

I have included an event method I commonly use for peer review and to help to fellow users..

 

It allows:

1. Multiple producers with different data types

2. Processes repecting order of production.

3. Allows for asynchronus checking of functional notifiers such as stop, start and abort.

4. In a non real time system it can include front panel interactions.

 

What I don't understand about it is what overheads, or thread priority changes that may be experienced by using this architecture (it solves a lot of problems for me).

 

Thanks in advance,

 

 

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
0 Kudos
Message 1 of 22
(7,132 Views)

I would think RT-FIFO, Event, Queue in that order. 

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 2 of 22
(7,124 Views)

Thanks for the response,

 

Can you explain why and by how much and any impact on task priority?

 

I would have guessed Queue faster than Event, the event model would need to maintain multiple queues (Event is a one-to-many relationship)  .

 

 

 

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
0 Kudos
Message 3 of 22
(7,119 Views)

My assumption of RT being the fastest is simply based on other posts that I have read, but I suppose it depends on what "fastest" means.  The time for the FP to respond or process data in the Consumer loop?  Unfortunately my experience with RT is vertually nil and this was based on other readings.  But as far as Queue and Events, Events will respond qucker to the FP.  But I think it's apples and oranges based on your example.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 4 of 22
(7,104 Views)
Solution
Accepted by topic author Timmar

Hi Timmar, 

 

Here is a KB article on some commonly asked questions about RT FIFOs:  http://digital.ni.com/public.nsf/allkb/7AE7075AF1B2C58486256AED006A029F?OpenDocument

 

The most relevant question is #4, which I have posted below.

 

What is the difference between RT FIFOs and Queues? 
Functionally, RT FIFOs and LabVIEW Queues are both First-in, First-out buffers. However, the following are the major differences between them: 

  • RT FIFOs execute deterministically in time-critical code and LabVIEW Queues do not. This comes from the fact that Queues use blocking calls when reading/writing to the shared resource while RT FIFOs use non-blocking calls. 
  • RT FIFOs are fixed size while the queues grow as elements are added to them.
  • RT FIFOs will execute the code even if there are errors at input. They can (and will) produce new errors and propagate existing errors.
  • Queues work with any data type, while the data types that can be used with RT FIFOs are limited. Usually any data type that involves additional memory allocations cannot be used with RT FIFOs in order to preserve determinism.

Let us know if there are any lingering questions!

 

Ryan

Applications Engineer
National Instruments
Message 5 of 22
(7,084 Views)

Are you running into a situation where the difference in time between producing an event, and consuming it, is actually causing your problems?  If not, this is not a question worth worrying about.  Use whatever is most appropriate for your application.

 

There's no need to make wild guesses - build a VI, benchmark and test!  The attached is a reasonable starting point, although I think the event structure may be slow due to setup time but may respond quickly once running.  If you experiment with this, you'll probably find that there's no definite answer to which is fastest.  Changing the size of the RT-FIFO, or of the queue, makes a big difference in speed.  At least in my testing, a single-element RT-FIFO is fastest, but an infinitely large queue is faster than a small queue, and a longer RT-FIFO is much slower than the single-element version.

 

It's important to realize that RT is not another word for Fast or Efficient, it's another word for Consistent.  For the purposes of real-time (deterministic) execution, it doesn't matter how fast the RT-FIFO functions are so long as they execute in exactly the same amount of time, every time (with the exception of a "forever" timeout value, of course).  You can use either a standard queue or an RT-FIFO to communicate between loops.  One use for an RT-FIFO is when a time-critical loop is enqueuing the data.  It guarantees that the amount of time needed to put data into the FIFO will not vary.  Enqueueing data in a standard queue will sometimes be faster than other times, depending on whether there is already space available in the queue or space needs to be allocated for the new element.  If this variation is unacceptable, then use an RT-FIFO; otherwise, the standard queue works just as well.

 

If the architecture shown in your image is working for you, I don't see any reason to change it.

 

EDIT: oops, almost forgot to attach the code I used for testing!

Event vs Queue.png

Message 6 of 22
(7,081 Views)

awesome nathan!

Applications Engineer
National Instruments
0 Kudos
Message 7 of 22
(7,075 Views)

@Ryan D wrote:

awesome nathan!


Thanks!  You know, there's a nifty "Kudos" button to the left of each message that you can use to express the same sentiment.

Message 8 of 22
(7,058 Views)

@nathand wrote:

@Ryan D wrote:

awesome nathan!


Thanks!  You know, there's a nifty "Kudos" button to the left of each message that you can use to express the same sentiment.


And accepted solution!

=====================
LabVIEW 2012


0 Kudos
Message 9 of 22
(7,057 Views)

kudos given where kudos due!

Applications Engineer
National Instruments
0 Kudos
Message 10 of 22
(7,053 Views)