Extending the jellyfish video room demo with a queue
Hey I am curious what a scalable way would be to add a queue in front of jellyfish rooms. I have a setup very similar to the jellyroom demo.
My current attempt is adding additional state for the queue to the
RoomService
module and somehow using the max_children
option of the DynamicSupervisor
to add to the queue but its getting super convoluted to manage the state
Would creating another GenServer like RoomQueue
to manage queueing rooms be a good idea? Any ideas would be appreciated8 Replies
Hi @Jdyn , I am not sure if I got you. What this queue would be responsible for?
Yeah so I have a setup where basically two people click "ready" and then a jellyfish WebRTC room starts.
if for example there are a max of 5 rooms already in progress, I want to implement a way for any rooms beyond 5 to wait in a queue until the 5 rooms are complete, then the next room starts when any current one finishes. The queue system would be responsible for starting rooms when a slot opens and remembering which room is next to start
should I create another genserver that checks every few seconds, the number of rooms open and a "list" of people waiting to see if it can start a new room?
I tried listening for the DOWN event of the rooms, but the logic for starting rooms when the queue was not full was getting messing... im not sure what a good approach would be.
And you would like to implement this in Jellyfish itself? To me this sounds like something that could be implemented in your custom backend logic. Your backend connects to the JF using our elixir or python server sdk and listens to notificaitons like RoomCreated and RoomRemoved or sth like this.
So basically it is your custom BE logic that queues new room requests and when it notices that JF has a free slot it creates a new room
and you can notice that JF has a free slot either by subscribing for notificaitons or periodically executing GET request on /room endpoint
Yeah so my plan is to implement it within my own BE. Sounds like a repeating timer in a GenSever and checking the room count is your recommended way. Is there any performance bottlenecks to consider going this route? If I were to get /room about every second or so?
You can subscribe for Jellyfish notifications
Notifications | Jellyfish
Jellyfish sends server side notifications whenever some important event occurs, e.g.:
So you don't need to execute GET requests every x seconds, just catch RoomCreated and RoomRemoved notifications
This was the missing piece I didn't think off. Got everything working thank you bro