GithubHelp home page GithubHelp logo

Comments (10)

jschneider1207 avatar jschneider1207 commented on June 2, 2024

After some more testing, it seems the sleep time required increases with the amount of parallel chains of:

producer_consumer -> producer_consumer -> consumer

I have subscribed to the one initial producer. With a parallelism of 10, the consumers need around 10-20ms sleep time (doesn't seem to be 100% consistant)

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

@sschneider1207 are your producer_consumer filtering events? Because I have just found a bug that, if the producer_consumer emits less events than it receives, the situation described above would happen. If not, if you can provide a way to reproduce this issue, it would be appreciated.

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

@sschneider1207 please try master as I have fixed the issue I mentioned above. If it is not enough, please try to include a mechanism to reproduce the error so I can further investigate it!

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

@sschneider1207 sorry, I didn't see you actually provided a link. Let me give it a try. :D

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

Actually, it seems I will need elastic search... so I won't be able to try it for now. Please give it a try and let me know.

from gen_stage.

jschneider1207 avatar jschneider1207 commented on June 2, 2024

@josevalim you don't need the elasticsearch bit, I'm just using the to create the initial list of events. My producer_consumers are just applying a single mapping function and returning the same number of events so I don't think this is the same issue. Here's an example minimum script that I put together that is roughly similar to what I'm doing that locks up after 4 batches:

alias Experimental.GenStage

defmodule A do
  use GenStage

  def init(:ok) do
    {:producer, nil}
  end

  def handle_demand(demand, nil) do
    events = Enum.to_list(1..demand)
    {:noreply, events, nil}
  end
end

defmodule B do
  use GenStage

  def init(:ok) do
    {:producer_consumer, nil}
  end

  def handle_events(events, _from, nil) do
    events = Enum.map(events, fn x -> List.duplicate(x, x) end)
    {:noreply, events, nil}
  end
end

defmodule C do
  use GenStage

  def init(:ok) do
    {:producer_consumer, nil}
  end

  def handle_events(events, _from, nil) do
    events = Enum.map(events, &Enum.reduce(&1, 0, fn x, acc -> x + acc end))
    {:noreply, events, nil}
  end
end

defmodule D do
  use GenStage

  def init(:ok) do
    {:consumer, nil}
  end

  def handle_events(events, _from, nil) do
    IO.inspect self
    {:noreply, [], nil}
  end
end

{:ok, a} = GenStage.start_link(A, :ok)
{:ok, b} = GenStage.start_link(B, :ok)
{:ok, c} = GenStage.start_link(C, :ok)
{:ok, d} = GenStage.start_link(D, :ok)

GenStage.sync_subscribe(d, to: c)
GenStage.sync_subscribe(c, to: b)
GenStage.sync_subscribe(b, to: a)

Process.sleep(:infinity)

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

@sschneider1207 this is awesome, thank you! I will investigate it tomorrow! :D

from gen_stage.

jschneider1207 avatar jschneider1207 commented on June 2, 2024

I'm not super familiar with how the different stage types are implemented, but I decided to turn tracing on one by one to see if I could notice any patterns. What I found was that enabling tracing on the C stage fixes it outright, so it might be at the root cause of this.
I also noticed that it seems like some of the ask messages might not be fully getting through:

  • Stage A receives an initial ask of 1000 items, followed by six asks for 500 items.
  • Stage B receives
    • one ask of 1000 items
    • four asks of 500 items
    • one batch of 1000 events
    • six batches of 500 events (so everything A sent)
  • Didn't record anything from stage C as tracing added enough delay (?) to fix issue
  • Stage D receives four batches of 500 events and locks up

Hopefully that is helpful.

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

This has been fixed in master. Can you please confirm you see it fixed too? :D

from gen_stage.

jschneider1207 avatar jschneider1207 commented on June 2, 2024

@josevalim Checked out the most recent commit and it is fixed!

from gen_stage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.