elixir-lang / gen_stage

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

Question about ConsumerSupervisor #253

Closed danbaranov closed 4 years ago

danbaranov commented 5 years ago

Hello!

In ConsumerSupervisor docs count_children function (https://hexdocs.pm/gen_stage/ConsumerSupervisor.html#count_children/1) returns active processes running. As stated in the doc the count of all actively running child processes managed by this supervisor. What does it precisely mean? Is it all consumer workers started by this ConsumerSupervisor or all process including maybe some genservers started by this workers?

The problem we have is gen_stage tree auto shutdown. We stop producer if all consumers done their job. We also track all consumers with Registry. At some moment of time sometimes we see no consumers left in Registry but active: 1 returned by count_children. Is it expected behaviour?

Thanks in advance!

josevalim commented 5 years ago

Because a child can be restarted, :active would return 0 if it is being restarted and :workers would return 1.

At some moment of time sometimes we see no consumers left in Registry

How do you know there are no consumers left in the Registry? For example, if you have a slow producer and fast consumers, you can constantly have no entries in the registry while you wait for new messages to be produced, but that doesn't mean the pipeline is over.

danbaranov commented 4 years ago

Correct answer in our case was: child was crashing shortly after start and restarting.

Thanks for the hint!