elixir-lang / gen_stage

Producer and consumer actors with back-pressure for Elixir
http://hexdocs.pm/gen_stage
1.48k stars 192 forks source link

Shuffle the demands on first dispatch for load balancing across consumers #277

Closed kenspirit closed 2 years ago

kenspirit commented 2 years ago

Based on the discussion in Broadway issue: The intention of random subscription in Subscriber does not work as expected, an option :shuffle_demands_on_first_dispatch is added to DemandDispatcher to allow shuffle the demands on first event dispatch.

I am not sure whether the default value should be false - aligned to previous behavior or true. Would the test case on shuffling enough?

josevalim commented 2 years ago

The direction looks great! I have dropped some comments to clean it up a bit. :)

josevalim commented 2 years ago

Thank you! :green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart:

Can you please try using this in Broadway? We should be able to pass this option whenever we have a DemandDispatcher.

kenspirit commented 2 years ago

I have already tried that in Broadway in that experiment project I tested before. After passing the option, the demand will not be all passed to the first consumer. :D