pba

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 :smiley: ]

        +-------------------+   +----------+
        | 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 TickerExecutorExecutionRequester 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 zip between two subscription event streams on a :consumer, than just going :manual on both subsctiptions ?

Edit: @admins I have found no Tags for GenStage or the Experimental Module. Would it be ok to add them?

Showing Posts 1 to 4

josevalim

josevalim

Creator of Elixir

Is there a way to announce to GenStage the actual consumption

I am not sure it is clear what you want to announce here? Which stage should tell the other stage what?

Is there a cleaner way to do a zip between two subscription event streams on a :consumer, than just going :manual on both subsctiptions ?

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

pba OP

Hi,
Thanks for answering!

Right now accepting a handle_events/3 call [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 :automatic subscriptions, but be able to freeze the demand. so that backpressure is built up on ExecutionRequester while i still accept events from Ticker.

Well it buys you an easy way to subscribe to a multitude of tickers in a structured (a.k.a. documented by @josevalim :smiley: ) way .

I only now realize that Ticker could provide a flexible rate-limiter for Flow pipes. Just zip in a :tick event stream, and you know exactly how many and how often items are processed, by controlling the emission behaviour of the Ticker producer.

Right now i have implemented:

  • rate per second
  • maximum item count per interval (e.g 1500 per day for free goolgle geolocation calls)
  • bucketed handling of [EDIT: :tick event allocation per interval].

So If you are undecided about Flow.zip I hope to find some time to separate that functionality from the Ticker and make a separate lib. Who knows who needs ratelimiting for Flow Pipes.

P.S. See you next week in Sofia :smiley:

josevalim

josevalim

Creator of Elixir

Well it buys you an easy way to subscribe to a multitude of tickers in a structured (a.k.a. documented by @josevalim :smiley: ) way .

Sorry, to be clearer, I meant only the ExecutionRequester being GenStage. You should keep the rest! :smiley:

So If you are undecided about Flow.zip

I will be glad to add that. Can you please open up an issue?

pba

pba OP

done: #83

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews