GenStage.DemandDispatcher (gen_stage v1.1.2) View Source

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.


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.


To start a producer with demands shuffled on first dispatch:

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