MassTransit and MaxConcurrentCalls not behaving as

2019-09-14 10:05发布

问题:

I'm using MassTransit as my messaging framework, running on top of Azure Service Bus. I'm running MassTransit from inside a WebJob (although I don't think that matters)

Now I'm trying to get MassTransit to process multiple messages at the same time, as I'm now dealing with messages that individually take a while to process. So to speed up performance, I don't want each message to be processed one by one.

I tried setting MaxConcurrentCalls to , for example, 30, but that doesn't seem to do it. Messages are still picked up by my consumer one by one.

I also tried setting the PrefetchCount to 5 etc, but it doesn't change anything.

What am I doing wrong? Any help is greatly appreciated

回答1:

So, I did some testing using MassTransit-Benchmark, and I'm able to get many concurrent consumers executing with Azure Service Bus using MassTransit 3.4.1.

With that in mind, realize that Azure is not fast, so if your consumer is doing nearly nothing (and completes in less than a few ms), it's unlikely that you'll see more than one at a time due to how poorly message delivery is with service bus. I had to add a delay of 3ms to the consumer to get up to 70-80 concurrent consumers. Without the delay, it was sitting around 2-3 concurrent consumers.

So, consider adjusting some settings. Also, there is a batch timeout you can set on the host that will help if you reduce it to under 10ms, even 5ms, if you are doing may small messages. A higher prefetch count helps as well.