multithreading - C# Blocking collection data handoff time intermittent -


data handoff in blocking collection taking time sometimes...

example code:
producer:

blockingcollection<byte[]> collection = new blockingcollection (5000); {     while (condition)     {         byte[] data = new byte[10240]         // fill data here.. read external source         collection.add(data);     } collection.completeadding(); } 

consumer:

{     while(!collection.iscompleteadding)     {         byte[] data = collection.take();         // write data disk..     } } 

both producer , consumer running on different task. runs sometime when adding array collection take around 50 milliseconds deal breaker , takes less 1 millisecond hand off data. theoretically consumer thread should not block when writing writing disk on separate thread.

it's boundedcapacity value you're passing constructor:

blockingcollection<byte[]> collection =      new blockingcollection (5000 /* <--- boundedcapacity */ ); 

you initializing blocking collection queue limited 5000 items. when there 5000 items in queue, producer blocked until there's empty slot again. limit makes sure queue satisfies little's law. you'll need analyse system optimal bound value, or can leave queue unbounded , write unit tests make sure doesn't overflow.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -