Comments (8)
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.
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
- some form of identity in order to be partitioned (ticker event scarcity)
- 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.
Oh, let's talk about it in Sofia then! Please say hi when you find me. :)
from gen_stage.
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.
@josevalim @paulbalomiri Do you mind sharing the solution you came up with?
from gen_stage.
@safwank there is a WIP implementation here: 67ad323
from gen_stage.
@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) andticker_stage
, a producer forticks
.
@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 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)
- Link required for ConsumerSupervisor? HOT 3
- Change default child :restart to :transient in ConsumerSupervisor HOT 1
- Doc typo in min_demand paragraph HOT 2
- ** (FunctionClauseError) no function clause matching in GenStage.Streamer.handle_info/2 HOT 11
- Release 0.14.2? HOT 2
- Dialyzer Error In GenState.async_subscribe/2 HOT 1
- [Feature request] add from ref to handle_demand. HOT 1
- Dialyzer error in GenStage.sync_subscribe/3 when using custom options HOT 1
- Version 0.14.3 released? HOT 1
- Question about ConsumerSupervisor HOT 2
- Init callback return option :subscribe_to looks too restrictive HOT 9
- Compilation error due to lackness of GenStage dependency HOT 2
- New release HOT 4
- `Endpoint.config_change/2` causes `undefined handle_info` HOT 6
- Improve documentation for GenStage.PartitionDispatcher HOT 1
- Usage of rate-limiter example is unclear HOT 4
- no function clause matching in GenStage.maybe_producer_cancel/2 HOT 2
- Fix CI
- Issue changing demand on-the-fly HOT 3
- There is typo in docs of GenStage module.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gen_stage.