3

Is the TPL Dataflow SingleProducerConstrained option referring to the number of source blocks or the minimum total parallelism degree of the source blocks?

i.e. if I only have one source block linking to a block with this option, must the MaxDegreeOfParallelism of the source be 1 or not?

VMAtm
  • 27,943
  • 17
  • 79
  • 125
user1249190
  • 337
  • 3
  • 13

1 Answers1

2

No, it means that (from MSDN):

methods like Post, Complete, Fault, and OfferMessage will never be called concurrently.

So you should set this property to true (false is the default value) if you're 100%-sure that the block will get messages in it from only one source at a given moment. Examples:

  • Block is target for only one linked source
  • You use lock around all the method sending something to the block
  • your app is single-threaded, and you sending messages not using the thread-pool or some other threading techniques.
  • etc.

Now back to your question:

if I only have one source block linking to a block with this option, must the MaxDegreeOfParallelism of the source be 1 or not?

It should be 1, as if it will be more than that, it can ruin some checks which are dropped with SingleProducerConstrained set to true.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • This seems to contradict this answer: https://stackoverflow.com/questions/22474082/singleproducerconstrained-and-maxdegreeofparallelism Are you sure about this? – Magnus Nov 06 '19 at 12:10
  • @Magnus I cannot see any contradictions. As this is an accepted answer, it probably better to ask the OP, did this answer helped him or not – VMAtm Nov 06 '19 at 12:28
  • The answer by @svick in https://stackoverflow.com/questions/22474082/singleproducerconstrained-and-maxdegreeofparallelism says that a source block with MaxDegreeOfParallelism > 1 is considerer a single producer, and if I understand your answer correctly you say it is not and that the target blocks need to have SingleProducerConstrained set to false. I just wanted to know how you came to this conclusion as the documentation seems to be a little bit fuzzy about this and other seems to say the opposite. Did you read it somewhere, did you test it, or other? – Magnus Nov 06 '19 at 13:53
  • @Magnus Maybe I tried some example and/or read the code on reference code base. Unfortunately, can’t say for sure right now. Maybe JSteward may help. – VMAtm Nov 06 '19 at 21:55