Consumer loop - unpredictable queue rate

Hello everyone,
I'm developing producer-consumer structure on RT and I have a strange problem. I'm receiving data from FPGA in producer loop and send it through queue to consumer loop. Next, they should go through network stream to Host. Because of the fact that consumer didn't keep up with producer (queue overflowed), I started to slow producer (the cost of this action is sending more data). It didn't help, so I added case structure in producer to send just half data to queue (the ones on TRUE in shift register).
This is the moment when I realized that sometimes closing LabVIEW environment and opening it again effects in speeding up queue transmission. Then, I can even accelerate producer loop and my queue doesn't overflow! And I can stop and run my program and it still works well.
I end up closing and opening LabVIEW and running my program all over again waiting for it to "click", because when it finally happens, I have no problem until next LabVIEW session.
Anyone have any idea what I could do wrong? Or how could I fix it?
Solved!
Go to Solution.
Attachments:
ProducerConsumerProblem.png ‏56 KB

Hello everyone,
at the beginning I'd like to apalogise for such late response. Something important came out and took a while, but I'm back now.
Firstly, aputman
- if I give "-1" to timeout I wouldn't be able to stop the loop if error occures after executing the loop. Maybe I care too much, but it shouldn't cause trouble here.
- I use 2 loop because I had some problems with network streaming data with just one timed loop and I found on LAVA forum someone's problem with TCP/IP. There was an advice to insert queue between receiving data from FPGA and streaming it to Host. The problem was connected to overflowing so tried implementing the advice.
ValkoA,
Reading your post I decided to change my code a bit. It occured that in spite of the fact that I want my timed loop to execute every 200ms (=collect 20'000 samples during each iteration) it collects between 10'000 and 30'000 samples FXP <14,5> (because of the feedback from Elements Remaining in FIFO, I think). So I changed "Number of Elements" in FIFO to 20'000. I made fixed size of queue buffer, too. Queue worked well then and my program was able to send data from RT to Host 20'000samples/200ms FXP <14,5>. However, it's too slow for me, and I need better quality than <14,5>.
Now I'm wondering if network stream is able to somehow slower all the process? When I tried making structure with just one Timed Loop with FIFO_Out and Write_to_stream inside it (so without any queues or producer/consumer), it couldn't send my arrays with FXP <20,5> fast enough - I received them on Host (network streaming) with latency, regardless how fast was my Timed Loop. For ex. my RT loop was during its 1000 iteration while my host was taking only 700th array of data. And then, suddendly reader on host stops throwing anything, and after a while it starts throw data very fast. There's a moment that the reader endpoint on host give ma arrays of zeros, and finally sometimes program stops. Maybe networks stream overflows.
Sorry for such long description...
And now here is my question: can I do something to speed up network stream a little? Single Timed Loop with FIFO_Out and Write_to_stream inside doesn't work at all for FXP <20,5>, regardless how fast I execute Timed Loop (program crashes). And the idea with producer/consumer doesn't work here too (queue overflows). FPGA sends data with 100kHz frequency. I fixed size of Network Stream.
Thank you

Similar Messages

  • Consumer loop very slow, queue size grows. How to speed up my consumer loop? As the array grows the slower it gets.

    LabView version: 2012
    OS: Windows XP SP3
    Hardware: USB NI cDAQ-9174 NI-9221
    Application: Oscilloscope
    I'm relatively new to LabView and I'm currently experiencing some performance issues with my project. I guess it has something to do with the way it's programmed. I'm hoping to get some tips from you guys.
    This is my producer loop. It should be capable of acquiring 100 000 Samples/s. I guess I've done this the right way and can't really be improved. Or am I mistaking?
    This is (part of) my consumer loop. It's too slow, the number of elements in the queue keeps getting bigger. I'm doing two types of calculations on the queue data. One for changing the scalling (a multiplication), one for changing the y-position (a summation). Because each time there are 10 000 samples acquired I have added an extra loop (inner loop). This loop splits the array into x samples when the requested samples are smaller than 10 000 or adds them when the requested samples are bigger than 10 000. This depends on the user input (time/dev).
    For example: when the user request 100 seconds of data to be plotted on a graph we get an array of 10 000 000 x 8. Is this considered big? Enlarging the array to that size is very very slow, the queue builds up rapidly.
    I don't know what really slows it down or how to 'debug' this properly. Transposing the array twice seems avoidable?
    Maybe I'm doing this in an inefficient way? Any thoughts that might help me?
    The VI's are attached.
    Thanks for your input.
    Attachments:
    Scope.zip ‏199 KB

    Thank you for your replies so far!
    LV_Pro,
    I agree it is a bit silly to plot more than 2000 points. I will change this. But even without a graph, the consumer loop seems to be unable to handle the speed.
    tst,
    1. Ok, I will change this
    2. Thank you for pointing this out. I implemented your technique and have some increased performance.
    Still not the speed I would expect from LabView. The system is 'stable' with a sample rate up to 100 Hz, increasing this makes my queue overflow.
    I must be doing something else wrong... Anymore ideas?
    Latest version of program in attachment.
    Attachments:
    Scope 1.zip ‏211 KB

  • Can anyone tell me what's wrong with my queue or producer consumer loop?

    A Labview engineer helped me with the overall structure of my program, necessitated by the fast data sample rate and post processing requirements. He recommended the producer/consumer loop and using one of the example files (Cont Acq graph voltage - int clk) to do the actual data acquistion. So I put together the loop and go my two channels of data acq going in the producer loop. However, nothing's getting picked up in the consumer loop and none of my data gets displayed over there.
    Anyone care to take a look at it and let me know what I'm doing wrong?
    Solved!
    Go to Solution.
    Attachments:
    P-C Yanmar Program.vi ‏296 KB

    Your Enque Element should be inside the while loop where you aquire the data.  As it is now, the data has to stop being aquired before you send the last set of aquired data.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to treat error handling in the consumer loop in the queue message handler structure?

    Hi,
    I'd like to know how to stop the producer loop(event loop) in the QMH structure when the error happened in the consumer loop.
    I've construct a demo code by myself as the attached image, but it's a pity that I have to create a recdundant indicator "End" to trigger the value change event to stop the program. This is not a good way to do it. Could someone give me some better idea how to deal with it? Very appreciated to you sharing ideas.

    Concerning your doubts about the "traditional" implementation of this pattern, I hear you. As I have written many times before, its main benefit is that it is easy to explain in a training class. It unfortunately has a lot of drawbacks.
    Tim's suggestion about User Events, is a good one. But to use it to the best advantage, you will need to get away from having everything on one block diagram. If you think about it there is no real need for the two loops to be on the same block diagram and a lot of really good reasons for them not to be. For example, if they are in separate VIs, they can both be event driven and any communication problems between loops evaporates.
    Its also more modular, easier to maintain, more reusable, etc...
    Check the link in my signature.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Data acquisition loop with queue

    What I would like to do is have a data acquisition loop that samples a load cell at 500Hz and have another loop that runs much slower to run a state machine and display some data in real time.  The reason I want to sample the load cell so fast is to filter out some noise.  Making producer/consumer loops with a queue kind of makes sense but I don't really care about all of the samples, I just want to be able to read a real time filtered signal at certain times.  I looked at having just two parallel loops, one to acquire the data and the other to run a test and retrieve a real-time signal when I want but not sure how to pass data between the loops without using a queue.  You can do it with local variables but you are at risk of a race condition.  I hope this make sense.  I am sure this is a simple problem I just don't know what direction to go.  Thanks

    Good Evening secr1973,
    It sounds like you are on the right track.  You already know about the producer/consumer architecture; this is almost always the first step to the separation that I think you are after.
    The step that I think you are missing is a Case Structure around the enqueue element VI.  You likely have some event or specific pattern that you are looking for in the input signal.  You can have the output from this algorithm (likely a boolean) determine which case of the Case Structure to execute (Case 1: enqueue the element or Case 2: Do not enqueue the element).
    This, of course, leads to processing being done in the producer loop, which is quite the opposite of what you are trying to accomplish with the producer/consumer architecture.  You will have to decide if your processing is very simple or more complicated.
    If it is easy/fast, you can likely get away with doing this processing in the producer loop.  My guess is that your program falls under the category of do-it-all-in-the-producer loop because you are only acquiring at 500 Hz.
    If the application requires faster acquisition rates or if the logic is going to require some processing, you may want to implement a double layer producer/consumer architecture.  In this setup, you would pass all of the data from the DAQ producer to a second loop (using queue #1) that determines what to do with the data (to enqueue or not to enqueue...) and, if appropriate, write to a queue (queue #2) that the third loop can read.  The third loop would be where your state machine executes.
    If you have a quad core machine, each of these steps will execute on its own core.  If not, you will have a little more thread swapping; not a huge concern in most cases.  Here, we get into the art of programming more than the science.
    In any event, I think you will be OK with a little processing for the enqueue or not algorithm in the producer loop.
    Regards,
    Charlie Piazza
    Staff Product Support Engineer, RF
    National Instruments

  • Producer consumer loop for serial comms

    I have an application where I am trying to read and write to a serial port using a producer consumer loop.  My producer consumer loop seems to work fine until I put the serial comm VIs in the consumer loop.  Prior to that my event structure in the producer loop seems to work fine and all the controls on the front panel send commands into the queue and the expected reaction happens in the consumer loop.  When I put serial comm VIs into the consumer loop the application will read the serial port but none of the other controls on the front panel ever get any reaction from the consumer loop.  I am not sure if I am using the producer consumer loops correctly when using comms at the same time.  Any help would be appreciated!!
    I have attached the VI for your inspection.
    Attachments:
    pinger comms.vi ‏65 KB

    You could probably continue with your original architecture as well.  Just put the check for bytes at port in the Read case of the consumer loop.  As you said, it takes 1-2 seconds for the device to send data.  So the original architecture didn't work because you were queueing up 20 reads per second in the timeout case, but the consumer loop was taking up to a second for a single byte to come in.
    If you check for bytes in the consumer loop, if none are there, the Read case will end quickly and won't wait for that byte to come in.
    You should also probably increase the timeout of the event structure to 100-200 mseconds or even more.  The event structure would still respond instantaneously to user interface events.  And you would only be generating the timeout case a few times per second.  Which means when a byte comes in, it would probably be sitting there only 100 mseconds or so before you read it.  Unless you go click happy and generate lots of other  events not allowing the timeout case to run.

  • Producer consumer loop array building

    Hello,
    I am trying to build an array in the consumer loop of a queued vi. This is the first time I have tried to use a producer-consumer structure since class many months ago. Each element is queued and sent to the consumer loop, and in that loop I want to build an array of the elements before I save it to disk. For some unknown reason I am having trouble accomplishing this. Usually I throw this stuff into a for loop, but here it isn't working.
    I am converting the random number to a string in the producer loop because when I build the real program I will be using strings.
    What am I missing?
    Tay
    Attachments:
    Loop test.vi ‏35 KB

    Just built your array in a shift register.
    (The error case is simply wired across.)
    Message Edited by altenbach on 05-16-2008 08:03 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    looptest.png ‏8 KB

  • Data delay in producer consumer loop?

    Hi,
    I've been creating an VI using producer consumer loop. In producer loop, every loop take 1000 samples at the rate of 40000/s(or 40000s/s devided by number of channels) and the consumer loop will average the data in a way corresponding to the "sampling rate" value on the front panel. The "sampling rate"represents the data rate on the chart and in the saved data file. If it's too slow,say 1 sample per second, then the producer loop will just wait for some time.
    So far the VI run smoothly, but there's one big problem. Each time I adjust the amplitude of input signal and the change doesn't show up on the chart untill several seconds later. When the "sampling rate" is really slow, the delay could be 1 minute! It's the first time I have ever used producer consumer loop and I 'm really confused of what causes this time delay.
    Could someone give me a hand with this?
    Thanks!
    Yaqiong
    Attachments:
    parallel.vi ‏73 KB

    You should consider further separating your tasks. For instance, the writing to file should be in its own task since file I/O can really cause delays in your processing. Also, I would separate your data processing (averaging) from the UI updates. The UI updates can be within a task that is using an event structure. It can get the data updates to update the chart but it can also quickly respond to the changes in your amplitude. I would also be very careful of the wait in your producer loop. This could starve the CPU.
    One last note. Your code could really benefit from a cleanup. Your coding style is quite a mess and it makes reading (and maintaining) your code much harder. For example, your code should generally read from left to right. Running wires backwards, having outputs on the left, lots of bends, etc all lead to messy code that is difficult to read.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Stopping producer consumer loop at the same time

    In my application I am using producer consumer architecture. In the producer loop, I am acquiring data, processing and outputting the result (feedback control system). Also in the same producer loop I am inputting all the data to a queue and then in the consumer loop I am writing data to a file. I have a stop control on the front panel and error from the queue and  error from the data acquisition all wired to OR gate to stop the while loop. ( I attached the picture of the code). Whenever I press stop form the front panel program wont completely stop. I think it is because consumer loop still running. Is there way to stop  the both loops at the same time. I tried creating local variable but it slows the program. Front panel stop control mechanical action is set to switch when released.
    Attachments:
    app.PNG ‏262 KB

    In the consumer loop you should check the error after the Read Queue function.
    TOn
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • One producer two consumer loops, dequeue same element in both consumers

    Hi!
    What is the best way for the following:
    I enqueu data in my producer loop. I need this data dequeue-d in both of my consumer loops, but I want to dequeu the same element in both loops.
    Of course if I put dequeues in both loop, then the second consumer loop will loose the odd elements and the first consumer loop will loose the even elements.
    thanks!
    Solved!
    Go to Solution.

    Blokk wrote:
    Hi!
    What is the best way for the following:
    I enqueu data in my producer loop. I need this data dequeue-d in both of my consumer loops, but I want to dequeu the same element in both loops.
    Of course if I put dequeues in both loop, then the second consumer loop will loose the odd elements and the first consumer loop will loose the even elements.
    thanks!
    Makes very little sence- that is, the problem is stated in such a way as to preclude an informative response
    Gerd wrote"
    either create two queues or use notifiers...
    Best regards,
    GerdW
    Usually, Gerd gives good advice but on this one I'm going to pick on him just a bit- I bet he rushed in just a tad without thinking about the premise of the OP's question - and Gerd I don't mean to sound mean, my appologies
    The question pre-supposes that to use a queue element twice in parallel it must be read twice.  This is false and led to less than optimal advice.  What about a template like shown in this snippet? 
    We can certainly dequeue once and spawn as many independant actions as we need within a single consumer loop!  Much more scalable than creating a queue for each action.
    Jeff

  • Basic Producer/Consumer loops for a newbie

    Labview neewbie here.
    I was looking at Producer Consumer loops.
    Can anybody give me a very basic explanation of how to set one up.
    I want to take readings from a HP 53131A counter and store them in an excel spreadsheet.
    I understand the part about labview slowing down as it opens the Excel file, and a seperate loop will help solve this.
    But I dont understad how to set up the Que function.
    Thanks.

    Multithreading will not make excell open faster but using concurrency you can have more than one operation operate ate different speeds.  The nice thing about the produce consumer model is that the if the consumer is slow or unreliable (freeses up) the producer doesnt care and will continue.  To use a queue is very simple, 1. create the queue, name it(optional) and give it a data type (ie int, array of floats ...)  in the produce loop use the enqueue vi to add items as needed to the queue, in the consumer dequeue these items (using a timeout = -1 the loop will wait for a new item and not consume resources)  the consumer can process the data acquired in the producer loop.
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • Consumer loop slowing down producer loop

    Hi All,
    I'm currently using a PXI to send commands to a chip, then retrieve the results with a DAQ. This process loops to populate a 256x50 array of values.
    Each time the loop is fully populated, I want to display the result onto a 3D plot, using 3d plot lvclass and plot helper. I noticed through the profiler and using timing functions in the loop that the 3D plot would take ~200 ms to update. The array would fully populate in about 100ms, so tripling the time to update was kind of nasty.
    I put the 3d plot into a consumer loop and everything else in a producer loop. It works fine, I don't mind about dropped frames, but it was running at the same speed. Apparently whenever the consumer loop executed, it would freeze completely the producer loop.
    Why is this? It seems like this fellow had the same problem:
    http://forums.ni.com/t5/LabVIEW/Producer-Consumer-Loops-not-independent/td-p/1115665
    But he "solved" it by removing the graph altogether. As showing the graph updating in real time is critically important, I can't just chuck it.

    No, an action engine is sometimes called a LabVIEW 2 Style global. They are basically a VI with a while loop and an unitialized shift register. They are useful when passing large amounts of data since it does not get copied. Also if you have transformations that are made on the data it is a single self contained VI that has data and actions which can be performed on it. Today a LVOOP implementation would be prefered. At any rate, this is a non-reentrant VI which will cause blocking to occur if called from two or more loops at the same time.
    Out of curiosity, what type of graphics card do you have in the PC? Would a better graphics card help?
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Is a Wait timer needed in a consumer loop?

    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?
    Solved!
    Go to Solution.

    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.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Why do i get error 1122 at dequeue element in consumer loop when i hit stop button

    when i hit stop button from vi, the producer loop stops, the consumer loop gets an error and stops without reading all the elements and then my check queue status loop continues to run becuase it never goes to 0.
    Any help?
    Solved!
    Go to Solution.
    Attachments:
    READ SIC AND LOG.vi ‏48 KB

    matt198717 wrote:
    i believe this is what you were talking about.  If youve got any advice or pointers for this VI please let me know.
    1. Your consumer loop should be using the Dequeue Elements.
    2. Your consumer loop should actually be releasing the queue in the STOP case.
    3. There is also no need for the polling to see how many elements are left in the queue.
    4. Your wait in the producer loop shold only be when there is no data in the buffer (you have it in the wrong case).
    5. Do not use the value from the Bytes At Port to tell the VISA Read how many bytes to read.  You tell the VISA Read to read more bytes than you would ever expect the message to be.  Let the termination character stop the read.
    6. Use a VISA read right after intializing your port to sync up your messages.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Serial Port Producer Consumer.png ‏32 KB

  • Consumer Loops Does not work. conflict.

    I am changing a operating project. I attached both of the projects which are the normal one working as desired and problematic one. In problematic project, only the main producer loop operates but consumers do not. I really do not understand why this happens. Most probably, I missed out something but I could not find. Can anyone help me on it. Thanks in advance.
    Egemen
    Attachments:
    Projects.zip ‏1965 KB

    Why are you making the user press the start button so many times to get this thing to run?  The way you have it set up currently, you are setting up those DAQ tasks over and over again until the Start button is pressed.  That is just very inefficient and likely causing memory leaks.  You should only have to hit it once to start your test.  After the first button press of the start, you should sequence through your state machine from Setup, VSC Setup, Record, and Running.  You should not be looking at any of the button presses during this time.
    You also have a lot of redundant waits.  Looking at the running case alone, I see three sets of waits that much happen for that single state.  Just have the outside loop have the wait.  None of the inner cases/states need waits.
    And I don't see your queues to your first set of consumer loops being closed.  The consumer loops are waiting for the queue to be destroyed in order to stop.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

Maybe you are looking for