View Source GenStage.DemandDispatcher (gen_stage v1.2.1)

A dispatcher that sends batches to the highest demand.

This is the default dispatcher used by GenStage. In order to avoid greedy consumers, it is recommended that all consumers have exactly the same maximum demand.

options

Options

The demand dispatcher accepts the following options on initialization:

  • :shuffle_demands_on_first_dispatch - when true, shuffle the initial demands list which is constructed on subscription before first dispatch. It prevents overloading the first consumer on first dispatch. Defaults to false.

  • :max_demand - the maximum demand expected on GenStage.ask/3. Defaults to the first demand asked.

examples

Examples

To start a producer with demands shuffled on first dispatch:

{:producer, state, dispatcher: {GenStage.DemandDispatcher, shuffle_demands_on_first_dispatch: true}}