sagar_k317
Hi! I am trying to build a solution and I need guidance as to what type of abstractions to use.
I have a pool of users and operators connected to my Phoenix app via channels. I have entries in my database for each operator and user along with their current state. Now I need to implement a basic FIFO queue of users. Whenever an operator’s state is ‘available’, I need to allocate the first member of the user queue to this operator and pop him out of the queue. The operator is now in a different state and will do some activities with this user through channels. The number of users can be less or more than the agents at any time.
I’d like to know if I should use an external library, like OPQ GitHub - fredwu/opq: Elixir queue! A simple, in-memory queue with worker pooling and rate limiting in Elixir. · GitHub, or implement Genstage on my own, or if there’s better solution to this entire problem.
Also, in order to make processing fast, I’m thinking of maintaining states of operators and users using Agent and then asynchronously update in the database.
Any sort of guidance will be really helpful.
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
- #elixirconf-us
- #ai
- #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 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Have you looked at Oban?
Or Broadway?
axelson
That’s an interesting problem statement. At first reading it seems like it might be good to model this with processes (using either GenServer or Agent). Can you explain more why you need to persist the operators state in the database? Could that instead be stored entirely in memory?
Based on my understanding of your description, OPQ doesn’t seem like a good fit because it simply has generic worker processes, whereas you need to assign users from the queue to a specific available operator.
I think what you primarily need is a FIFO queue of users, then whenever an operator becomes available, it can request the next user from the queue. That way the operators don’t need to talk to each other, instead they just need to pull items off of the shared queue. Depending on your scaling needs a single GenServer holding the queue of users should work fine (Look at the erlang queue module).
kokolegorille
It’s not really a producer consumer problem, I think it’s more related to limited resource access (where operators are those limited resources)… In which case I would look for design like poolboy, with checkin/checkout.
There is Erlang :queue module to manage queue.
If You want to be fast, You shouldn’t think in terms of database. As mentionned by @axelson there are many ways to go faster than db. At most, I would use db to load state for a GenServer. When I really need speed, I reach for ETS.
I don’t think GenStage is a good fit, it’s more like a pipeline, with successive steps.
It looks like a call center model, or a helpdesk service.
There are similar ideas in voip asterisk server Asterisk Agents - VoIP-Info
sagar_k317
Thanks for the reply! Actually our business requires us to store various states in the Database because those will be used for deciding the billing and also analytics (I know for analytics we can use other approaches). The number of users can go upto 5000 at peak.
sagar_k317
Thank you! Looking into ETS
sagar_k317
Oban too has generic workers which won’t fit in my use case.
xlphs
Operator sounds like a Rabbitmq consumer that can only handle 1 task at a time, and user queue is Rabbitmq messages queued up under a certain topic (channel). This is more of a routing problem than consumer/producer problem. I don’t have any concrete implementation I can suggest but rabbitmq is open source so you could look at their code