Search⌘ K
AI Features

Understand Consumer Demand

Explore how consumer demand operates within GenStage to manage event flow efficiently. Understand the roles of min_demand and max_demand in controlling batch sizes, and learn to configure these settings for optimal pipeline performance.

Consumer demand

We previously saw that PageProducer was asked for 1,000 events. We may wonder where the number comes from. By default, stages of the :consumer and :producer_consumer type ensure that the demand for new events is between 500 and 1,000. We can configure this through the min_demand and max_demand settings. When a consumer subscribes to a producer in the init/1 function, we pass a tuple with some configuration options:

#`subscribe_to` options can be a list of tuples.
sub_opts = [{PageProducer, min_demand: 500, max_demand: 1000}]
{:consumer, initial_state, subscribe_to: sub_opts}
...