I am designing solution for multi-threaded Producer Consumer problem.
product are very much in numbers (around 100,000) because consumer runs once in an Hour.
there are multiple producer threads and one consumer thread.
Consumer thread is a Task that executes every hour.
Consumer thread saves data to database for the last hour, for the current hour, it leaves it in the product collection.
I begin writing solution as described in following post classic producer consumer pattern using blockingcollection and tasks .net 4 TPL
I am thinking more optimized way of producing and consuming products, for this i thought not to check for last hour in each and every row of product collection, instead use ConcurrentDictionary with key as Hour(DateTime).
Thus instead of using Product I want to use something like ConcurrentDictionary>
I think by using ConcurrentDictionary on Hour(DateTime) Key, Consumer can easily pick last hour Products and save it to database without having burden of filtering products by hour.
I thought to use BlockingCollection in following ways but both seems not correct.
Using BlockingCollection>> does not seems good as inside it there will be only one entry that itself is a dictionary.
Using ConcurrentDictionary>> does not seems to give advantages of BlockingCollection collection as it is not directly accessed by the consumer/producer.
How can I use BlockingCollection in this scenario? Am I on the right approach?
EDIT: This server takes very high load i.e. receives 4 MB of data every 30 seconds and process it that took 50 time more of memory. Its a server that is expected to run for months.