Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ConcurrencyLimit and PrefetchCount?

What is the difference between ConcurrencyLimit and PrefetchCount in masstransit? and what is the optimize configuration for them.

like image 511
sajjad kalantari Avatar asked Jul 29 '19 17:07

sajjad kalantari


1 Answers

PrefetchCount is a broker-level setting. It indicates to RabbitMQ (or Azure Service Bus) how many messages should be pushed to the client application so that they're ready for processing.

In addition, if a RabbitMQ consumer has prefetch space available, published messages are immediately written to the consumer, reducing overall message latency. Because of this, having prefetch space available on a consumer can improve overall message throughput.

ConcurrencyLimit is a client-level thing, that indicates the maximum number of messages that will be consumed concurrently. This may be due to resource limits, or to avoid database overloading, etc.

In cases where messages process very quickly, but cannot be processed too concurrently, a limit may be set using ConcurrencyLimit to avoid overloading the CPU. However, super fast message consumption increases the sensitivity to the time it takes to request more messages from the broker. So a higher prefetch count is recommended for fast message consumers.

For slow consumers, such as those that make external calls, where the consumer duration is more dependent on slow external systems, a higher concurrency limit can increase overall throughput. In this case, a higher prefetch count doesn't add much, but it should at least be as high as the concurrency limit.

If you're scaling out (competing consumer), then it's a tuning exercise to figure out how many instances, concurrent consumers, and prefetched messages make sense.

For example, we have a database consumer, that can run up to 100 concurrent transactions on the SQL server before it starts to block, so we run a concurrency limit of 100 with a prefetch of 110.

like image 129
Chris Patterson Avatar answered Nov 05 '22 02:11

Chris Patterson