05-22-2019 05:40 AM
In Producer and consumer which loop will run fast and why?
05-22-2019 06:31 AM
Often, they'll run at the same average speed. Sometimes a consumer will purposely run slower and do "batch processing".
Generally, the reason one would *choose* a producer/consumer architecture is to unencumber the producer loop. So generally, the producer is the loop that *needs* to run fast without interruption.
- Kevin P
05-22-2019 06:32 AM
That's an interesting question. Please tell us what you think is a sensible answer (I would maintain that there is no "correct" answer, as you haven't defined what you mean by the speed of the loop).
Bob Schor
05-23-2019 12:48 AM
As per my understanding , I think it depends on the application to be designed which decides which loop to work faster.
Like few applications require the producer loop to be faster so that it produces queued data which is then processed by the consumer loop at its own pace.
Some applications require the consumer loop to run faster to buffer the queued data and in some applications both the loops run at same pace.
This is my understanding.Please correct me if I'm wrong somewhere 🙂
05-24-2019 09:11 AM
Most situations that I've encountered has the Producer running at a relatively-fixed speed, usually driven by a "time-specified" requirement (such as acquiring 1000 points from a DAQ card at 1kHz, a process that takes 1 second but can't be "delayed" by having 10 seconds of processing in the same loop) and one that takes a "flexible" length of time, typically running "as fast as it can" in an attempt to "keep up with" the rate that data are being "produced" by the Producer. Usually the transfer mechanism (such as a Queue) can "buffer" data to allow the Consumer to "take a little extra time when needed" (say, to open files or query a database), but you don't generally want the Consumer to run significantly slower than the Producer. Note that just as the Producer often "waits" for much of its Loop time (in the DAQ example noted above, >99% of the time the Producer is waiting for the DAQmx Read to finish and produce the data on its output lines), a well-behaved Consumer should strive to "Consume" at, or slightly faster, than the rate that the Producer "produces".
Bob Schor