Quote from amazingIndustry:
It makes sense to observe this about BoundedCapacity, because it most likely runs other checks on the internal queue which may add overhead. Your numbers still sound low. I ran the same test on my very old 2core laptop and still get to 11million items per second. Have you followed my advice to setup an Action<T> instead of calling a method each time? Or do you observe the 5mil messages/sec while incrementing the counter directly within the actionblock?
After removing a bool check (if the background thread should keep processing) on the producer side, speed is above 10 million items per second.
Constructor:
_actionBlock = new ActionBlock<long>(l => { _handled++; }, new ExecutionDataflowBlockOptions() { SingleProducerConstrained = true });
On background producer thread:
while (true)
{
if (_actionBlock.InputCount <= 1000000)
_actionBlock.Post(1);
}
If I add the method call back in on the consumer side, speed drops to the 5 million items per second rate.
Academically, it's interesting to see that difference. But if I were to use this code to feed tick data to a strategy, I would need to eventually call a private method. Implementing a strategy within a lamda expression which isn't a option for us.
