Are there any plans for a bounded BufferBlock?

Answered Are there any plans for a bounded BufferBlock?

All Replies

  • Thursday, November 04, 2010 9:38 PM
    Owner
     
     Answered

    Hi Steve-

    We're definitely considering it, so it's good to know you're interested.  Can you elaborate on how you'd like to use it and on the various behaviors you'd expect from it?  For example, if code explicitly Post's to such a bounded buffer, would you want that Post to block until room was available, or would you want it to return false indicating that the data couldn't be accepted?  Similarly, I assume that you'd want a bounded buffer to postpone messages that it didn't yet have room to accept?

  • Friday, February 04, 2011 5:14 PM
     
     
    An unbounded buffer is seldomly a good idea imo. It leads to heisenbugs (sporadic OOM). There is really no difference between an ordinary race condition and an unbounded buffer.
  • Friday, February 04, 2011 5:32 PM
    Owner
     
     Answered
    The latest preview of TPL Dataflow, available at http://msdn.microsoft.com/en-us/devlabs/gg585582, has bounding support built into BufferBlock.  You can configure it to be either unbounded or bounded with a capacity supplied at construction.
  • Friday, March 04, 2011 9:42 AM
     
      Has Code

    Hello Stephen et al.,

    I've set up dataflow using a bounded BufferBlock in the middle, assuming this would allow me to throttle data flow.  I should say I downloaded the library only yesterday so I'd assume I have the version with the bounded BufferBlock support.

    Here's a code snippet that shows how the blocks are created and connected:

       myDirectoryProcessor = new TransformManyBlock<Directory, File>((Func<Directory, IEnumerable<File>>) ProcessDirectory,
                       new DataflowBlockOptions(TaskScheduler.Default));
       
       myFileProcessor = new ActionBlock<File>((Action<File>) ProcessFile, new DataflowBlockOptions(TaskScheduler.Default, 16));
    
       var bufferBlock = new BufferBlock<File>(10);
    
       myDirectoryProcessor.LinkTo(bufferBlock);
       bufferBlock.LinkTo(myFileProcessor);
    
    

    It just doesn't seem to work, frankly the BufferBlock doesn't actually do any throttling.  The 'InputCount' property on "myFileProcessor" keeps growing (the 'ProcessDirectory' method produces results faster than the 'ProcessFile' method can handle, even if the latter is executed with a parallelism of 16 in this case).

    It's well possible that I've missed something if so please let me know.

    [Update] Sorry, my bad, indeed I was missing something.  The fact that the file processor block is greedy means it takes items from the buffer as soon as any are added, this really does make the buffer pointless.  I've changed the file processor to be non-greedy, and lo-and-behold! it works as expected, and the throttling effect works.[/Update]

    Thanks
    Matt