Mediasoup sockets with PM2 and shared room, peer objects

Hi,

Current Mediasoup demo is designed for the single cpu node js process. If I use the PM2 multple CPUs, and socket io, it works and can connect the right socket in the room.

But then the workers,routers, transports, producers consumers etc are the objects only in that process and not available to others, this causes the problem.

Do you have any solution where the mediasoup demo is scalable with nodej multiple CPUs and PM2, socket io and the mediasoup producers, consumers shared across them?

There’s establishing a pipetransport between the two objects over local network, or you could re-write some of the code to use Node.JS clusters.

Thanks a lot for quick response, Appreciate!

I know the pipetransport, but I guess thats most suited for the one to many scenario. It might not solve the problem. For e.g. I want to have a setup whereby multiple meetings will happen in parallel. Some with only 2/3 participants and some with 250+ participants. Now, if user joins the socket on other CPU and I create the pipetransport for so many participants between the CPU-1 & CPU2 & CPU-n, it would be really very high number of transports and back and forth. Thus, this query.

Does mediasoup have any internal mechanism to store the room, producers, consumers inside the code itself and exchange between workers?
If not can it be done at the system level, which can handle it seamlessly?

I know the pipetransport, but I guess thats most suited for the one to many scenario.
It’s perfect for one-to-many or many-to-many, so that’d be incorrect.

It might not solve the problem. For e.g. I want to have a setup whereby multiple meetings will happen in parallel. Some with only 2/3 participants and some with 250+ participants.
It certainly would, you would just need in place good code to avoid CPU overflow, and prevent sitting servers.

Now, if user joins the socket on other CPU and I create the pipetransport for so many participants between the CPU-1 & CPU2 & CPU-n, it would be really very high number of transports and back and forth. Thus, this query.
Yup and that’s the game! You need to figure that out for your application to balance/scale well.


PipeTransports is the key for many to many and one to many broadcasting, when you connect two routers locally or remotely the two pipetransports can now re-produce/consume off each other and send the media where it needs to go.

This won’t be easy and it’s a bit of a secret how some do it.

1 Like

Hi Cosmosis T,

I know the pipetransport, but I guess thats most suited for the one to many scenario.
Thanks a lot for the response. I know that many to many would work same way like one to many. But I was skeptical about the capacity. Your response is giving me confidence. I shall definitely try the pipetransport for the max transports back and forth from 4 CPU cores, while each CPU also has the participants joined there as well.

It might not solve the problem. For e.g. I want to have a setup whereby multiple meetings will happen in parallel. Some with only 2/3 participants and some with 250+ participants.
As far as the CPU overflow is concerned, that would be managed by the PM2 internally by distributing the socket connections to various CPUs.

This won’t be easy and it’s a bit of a secret how some do it.
I shall try . Thanks a lot for quick and point to point response.