GithubHelp home page GithubHelp logo

Comments (8)

josevalim avatar josevalim commented on June 2, 2024

Hi @paulbalomiri,

So I have just realized zip is harder conceptually then we first thought. The issue is, imagine you are zipping two flows into one. The new flow will actually be made of four stages:

[A1] [A2] [A3] [A4]   [B1] [B2] [B3] [B4]

      ... all A connected to Z ...
      ... all B connected to Z ...

        [Z1]   [Z2]   [Z3]   [Z4]

The problem is, because flow is by default partitioned, every event happening in B, in this case, the ticker, will be delivered to a different partition per time. If the event is always of the same value, it will always be delivered to the same partition which means events routing to the other partitions will never be emitted.

One option is to set the stages in B to use the broadcast dispatcher. In your case it would work exactly as expected.

So implementation-wise this is not a problem but rather how we want to expose this problem in the API. One option is to have two different zip functions: partitioned_zip and broadcast_zip. On both cases A behaves the same but you can configure how B works. Another option is to provide a generic API, such as Flow.zip(left, left_opts, right, right_opts, options) that allows you to customize exactly how which side will behave.

Yet another option is to kip the Flow.zip(left, right, options) API and allow a tuple format to be given:

Flow.zip({left, left_options}, right, options)

This API could also be useful in the merge function, where you may want to specify different dispatchers per flow being merged. For those reasons I am inclined to go with the tuple format.

Any thoughts or questions before I move forward?

from gen_stage.

paulbalomiri avatar paulbalomiri commented on June 2, 2024

If the event is always of the same value, it will always be delivered to the same partition

I guess this means the :tick events need either

  1. some form of identity in order to be partitioned (ticker event scarcity)
  2. as you say a broadcaster, (just ratelimiting of the flow, which scales with the partition count)

(1) could be achieved by piping through |>Stream.with_index() for each flow before Flow.zip() merging.

I'm not sure I understand why partitioned_zip and broadcast_zip would be inherent to the zip functionality.

@josevalim I'm still thinking about this, and if it's not too late i'd like to add to this answer tomorrow, on the trip to sofia. I will not be the driver :D

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

Oh, let's talk about it in Sofia then! Please say hi when you find me. :)

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

After some discussion in private, we have identified another solution to @paulbalomiri's problem, so we are closing this although the work has been published to a branch. If another person shows interest in this feature, we can gladly reopen the discussion.

from gen_stage.

safwank avatar safwank commented on June 2, 2024

@josevalim @paulbalomiri Do you mind sharing the solution you came up with?

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

@safwank there is a WIP implementation here: 67ad323

from gen_stage.

paulbalomiri avatar paulbalomiri commented on June 2, 2024

@safwank I ended up not using a zip, but a consumer using ask on what would be left and right in the zip arguments.

Ended up creating 2 libraries (not published as of now - see below), which i called

  • table_stage, a generic postgres producer (fed from rows) and
  • ticker_stage, a producer for ticks.

@josevalim Is it ok to call packages *_stage when publishing on hex.pm and the source on github?

It might take one more month until i publish the packages as I am busy working on a new production release for my company, which also includes polish for these libraries.

from gen_stage.

josevalim avatar josevalim commented on June 2, 2024

@josevalim Is it ok to call packages *_stage when publishing on hex.pm and the source on github?

That sounds great actually. :)

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.