pba
I am writing a rate-limiter for a code executer using Genstage. My code looks like this [hope the post is not too long
]
+-------------------+ +----------+
| ExecutionRequester| | Ticker |
| :producer | |:producer |
+-------------------+ +----------+
| +-------------------+ |
:exec_request| TickerExecutor | |:tick
+------> :producer_consumer<----+
+-------------------+
|
| +--------------+
| |ResultConsumer|
+---> :consumer |
+--------------+
TickerExecutor should consume from both ExecutionRequester and Ticker, and do a zip operation:
Only 1 :exec_request is allowed for 1 :tick event produced by Ticker.
I have implemented :manual subscription handling for the TickerExecutor → ExecutionRequester subscription, but felt like 90% of the code (:min_demand, :max_demand) is reimplementing GenStages :automatic subscription. I’m, weary of doing the same for the Ticker subscription, before asking.
As of now I’m consuming and wasting :tick events when TickerExecutor is starved of :exec_requests
Thus my 2 questions:
- Is there a way to announce to GenStage the actual consumption [Edit: or rejection] of events, and not just the delivery via
GenStage.handle_events/3? - Is there a cleaner way to do a
zipbetween two subscription event streams on a:consumer, than just going:manualon both subsctiptions ?
Edit: @admins I have found no Tags for GenStage or the Experimental Module. Would it be ok to add them?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
josevalim
I am not sure it is clear what you want to announce here? Which stage should tell the other stage what?
So after thinking about the use case you described above, I am wondering if it wouldn’t be better for you to have a ExecutionRequester as a separate process that you request every time there is a tick. With max_Demand of 1 and a zip, GenStage is not buying you anything for the first three processes: it would be quite equivalent to using regular processes.
The only scenario zip would make in GenStage is if we could still have a high demand value (and you would have back-pressure if one of the sources is slower but typically not). If we ever implement something like this, it would be as Flow.zip.
pba
Hi,
Thanks for answering!
Right now accepting a
handle_events/3call [EDIT: in a:consumer] is the same has having actually handled the events. In reality the Consmer can wait for events from another subscription. What I would like is to use:automaticsubscriptions, but be able to freeze the demand. so that backpressure is built up onExecutionRequesterwhile i still accept events fromTicker.Well it buys you an easy way to subscribe to a multitude of tickers in a structured (a.k.a. documented by @josevalim
) way .
I only now realize that
Tickercould provide a flexible rate-limiter forFlowpipes. Just zip in a:tickevent stream, and you know exactly how many and how often items are processed, by controlling the emission behaviour of theTickerproducer.Right now i have implemented:
:tickevent allocation per interval].So If you are undecided about
Flow.zipI hope to find some time to separate that functionality from the Ticker and make a separate lib. Who knows who needs ratelimiting forFlowPipes.P.S. See you next week in Sofia
josevalim
Sorry, to be clearer, I meant only the
ExecutionRequesterbeing GenStage. You should keep the rest!I will be glad to add that. Can you please open up an issue?
pba
done: #83