D4no0
Suppose we have a project, that uses ecto with a connection pool of 20 connections.
Now the system produces events, however the production process might take long time, and is a database query that uses a connection. I have 2 problems that I need to solve: rate limiting and congestion.
The rate limiting can be solved easily with broadway/genstage.
Now the second problem is related to the fact that all consumers should receive events (they all receive different types of events). The problem appears when a producer spams a lot of events for a single consumer type, while they get processed for that consumer, others don’t receive anything.
A naive approach would be to create a queue with different lists for each consumer and round robbin from that list. Is there a different, maybe more official way to do this?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
cmo
If you want gauranteed at least once delivery you might be in the market for a proper message queue such as RabbitMQ or Kafka or .
joey_the_snake
I think a GenStage producer using the demand dispatcher (the default) does what you want.
If all your consumers are using the same values for
max_demandandmin_demandthen it should distribute the events fairly across consumersYou just have to be careful picking the values of
max_demandandmin_demandto ensure you’re not exhausting your DB pool. Keep in mind this is the behaviour of those parameters:D4no0
Ok, this seems a step in the right direction, what I can’t understand is how do I limit the connection pool this way. In my understanding this should be implemented in the following way: create a
DemandDispatcherand for each type of message a consumer.Now we will have some nasty problems:
If each consumer uses a database connection, we can limit the total numbers of connections only by the numbers of consumers. This is also very bad because consumer will always be limited to 1 connection, taking long time to process when only one type of events are required.
In my understanding, no genstage mechanism can solve the problem of congestion. The solution I think would be suited for this case is a 2 stage processing pipeline.
A custom producer will produce events in correct order and send them via something like rabbitmq (to guarantee delivery).
The second stage will be a broadway pipeline with number of processors equal to maximum pool of connections available, that will process all the events and ensure the limit is not hit on connection pool.