multithreading - Application design for parallel collection processing -


i'm experimenting system.collections.concurrent namespace have problem implementing design.

  1. my input queue (concurrentqueue) getting populated fine thread doing i/o @ startup read , parse.
  2. next kick off parallel.foreach() on input queue. i'm doing i/o bound work on each item.
  3. a log item created each item processed in foreach() , dropped result queue.

what kick off logging start reading input because may not able fit of log items in memory. best way wait items land in result queue? there design patterns or examples should looking at?

i think pattern you're looking producer/consumer pattern. more specifically, can have producer/consumer implementation built around tpl , blockingcollection.

the main concepts want read are:

  1. task,
  2. blockingcollection,
  3. taskfactory.continuewhenall(will allow perform action when set of tasks/threads finished running).
  4. bounding , blocking in blockingcollection. allows set maximum size output collection (for memory reasons) , producer thread(s) wait consumers pick elements in case maximum size specify reached.
  5. blockingcollection.completeadding , blockingcollection.iscompleted can used synchronize producers , consumers (producer can when it's finished, consumer can check , keep running until producer(s) finised).

a more complete sample in second article linked.

in case think want consumer pick things result queue , dispose of them possible (write them logging store, or similar).

so final collection, dump log items should blockingcollection, not concurrentqueue.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -