# About single Router consumers limit and "pipeToRouter"

**URL:** <https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766>\
**Category:** Deployment & Scalability\
**Created:** [December 9, 2022, 1:27pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766 "2022-12-09T13:27:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 9, 2022, 1:27pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/1 "2022-12-09T13:27:29Z")

</div>

Hi  
I have a question about single Router consumers limit, I’m sorry if this question has been mentioned, because I went through almost all topic about pipetorouter and didn’t find a clear answer, here is my question:  
We know that a Router can support about 500 consumers. For example, I have a Router1, which already contains 100 producers and 500 consumers. Now I transport 100 producers in Router1 to Router2 use pipeToRouter.  
question 1: Is the number of producers in Router1 also limited by 500? In my example, Router1 contains 100 producers and 500 consumers. Is this feasible? What about 500 producers + 500 consumers in a single Router?  
question 2: How many consumers are there in Router1 now? 501 or 600?

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [December 9, 2022, 1:41pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/2 "2022-12-09T13:41:04Z")

</div>

Router have no consumer limit, it is worker which have the limitation. Now 500 is for a normal CPU it differse between machines so if you have a heavy machine then you can support more than 500 per worker.

Lets assume it is 500.

The other thing is 500 is sum of producers + consumers, not 100% sure about it. But producer do take around same cpu as the producer takes.

As for question 2 on router 1 you will have 600 consumers after piping.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 9, 2022, 1:48pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/3 "2022-12-09T13:48:17Z")

</div>

Thank you so much for your quick reply, yes, I know that “Depending on the host CPU capabilities, a mediasoup C++ subprocess can typically handle over ~500 consumers in total.”, thank you for the reminder。

“As for question 2 on router 1 you will have 501 consumers after piping.”  
this is exactly the definitive answer I desperately needed to know, thank you very much.

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [December 9, 2022, 1:50pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/4 "2022-12-09T13:50:37Z")

</div>

Sorry it will be 600, you are piping 100 producers, so 500+100 = 600, I was assuming that 1 producer was being piped.

You must be disappointed after hearing this 🙂

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 9, 2022, 1:56pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/5 "2022-12-09T13:56:55Z")

</div>

Yes, Haha, this will make it a lot harder to scale mediasoup, because a producer in a Worker whose processing capacity has reached its upper limit will be consumed at any time.Is there any good solution?

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [December 9, 2022, 2:07pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/6 "2022-12-09T14:07:11Z")

</div>

You will have to take some measurements before hand to tackle that. You must not use worker to its full capacity leave some space for sudden spikes.

There can be multiple solutions to this as per you usecase.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 9, 2022, 2:15pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/7 "2022-12-09T14:15:36Z")

</div>

Ok, thank you very much for your reply, I now have a clear direction and know what to do, thank you again and wish you a happy life.

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [December 9, 2022, 2:21pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/8 "2022-12-09T14:21:12Z")

</div>

No problem, there are some resources on this platform about scaling, you can search and read through them. I can share you the ones which I followed in some time.

You must read them and understand them before starting working on scalability otherwise you may end up on dead end.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 9, 2022, 2:39pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/9 "2022-12-09T14:39:44Z")

</div>

Ok, thanks for the reminder, I’m reading some topics related to scaling, and there is indeed a lot of work to be done, requiring careful planning. 😇

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [December 9, 2022, 3:25pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/10 "2022-12-09T15:25:49Z")

</div>

Here is the list of topics I followed, they cover scalability deeply enough to get started:

> [@CPU/Bandwidth results for many-to-many rooms in production.](https://mediasoup.discourse.group/t/cpu-bandwidth-results-for-many-to-many-rooms-in-production/4423):
>
> Between 15 rooms with users ranging anywhere from 1 → 11 (currently). Totaling a maximum of 53 viewers, and 27 broadcasters. Results may differ with users just sending audio broadcasts, but setup uses pipetransporting and all sorts for maximum scalability. On 5 servers, CPU usages is at about 2-20%overall CPU usage as displayed in the picture. SPECS: 4vCore @ 8GB RAM (HDD who cares) and 1Gbp/s networking unmetered. Due to my setup and rooms expanding past a single core’s ability,…

> [@How to manage rooms, workers etc when using multiple server/node clustering?](https://mediasoup.discourse.group/t/how-to-manage-rooms-workers-etc-when-using-multiple-server-node-clustering/4638):
>
> I am using node clusters to divide loads on all cores of cpus, doing the same for socket io using io redis adapter to distribute sockets between cores. Socket will be connected to any of the cores. I am having issue here which is user’s socket gets connected to core 1, while room is on core 2 and workers, producers etc all references are on core 2 as well, so socket can’t access all that stuff of the room he want to join in or to perform any other action because they are on separate process. I…

> [@access workers, routers, transports objects from one node process to another](https://mediasoup.discourse.group/t/access-workers-routers-transports-objects-from-one-node-process-to-another/4403):
>
> Is there any way I can access workers, routers, transports objects from one node process to another? I was thinking that may be I can construct object of workers, routers, transports from their respective process ids? I am actually planning to make multiple processes of my app i.e run on all cores of my machine. Now that my workers, routers, transports instances are on one of the processes and I need to access them in another process of my node app? Is their any way I can do that? EDIT: You …

> [@Mediasoup Scaling resource](https://mediasoup.discourse.group/t/mediasoup-scaling-resource/1866):
>
> I’ve been trying to wrap my head around mediasoup scaling and combing through the resources available to understand the constraints. I put this together for my own understanding but if it’s correct, I hope it might also be useful to other people who join the community. I’d appreciate any feedback and also happy to refine this into something more complete, maybe add some diagrams if it’s interesting to people. This information is not the result of benchmarking myself, instead this is a result of…

> [@Maximum number of consumers per worker is 500 w.r.t CPU?](https://mediasoup.discourse.group/t/maximum-number-of-consumers-per-worker-is-500-w-r-t-cpu/4058):
>
> It is mentioned in the official docs here: [mediasoup :: Scalability](https://mediasoup.org/documentation/v3/scalability/) and in discourse topic as well here: [A room with 100 participants](https://mediasoup.discourse.group/t/a-room-with-100-participants/1092) Does this mean that there is hard limit of 500 for a worker or does this mean that if I use high end server then the same worker can handle more than 500 consumers? I am using AWS instance g4dn.8xlarge which is a high end server and it has 32 cores. I am using 1 worker per call so each call has it’s own worker. I am showing max 20 streams to each participant so…

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 9, 2022, 3:50pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/11 "2022-12-09T15:50:12Z")

</div>

Thank you very much, these materials are like treasures to me, I will read and understand carefully, I am lucky to join this warm community, I am new to this great product of mediasoup, but I will study hard and Grow and help others in the future. Like you! 😋

---

<div class="post-metadata">

**Author:** ![BronzedBroth](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BronzedBroth](https://mediasoup.discourse.group/u/BronzedBroth)\
**Post date:** [December 10, 2022, 3:12am UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/12 "2022-12-10T03:12:55Z")

</div>

A worker does not need to use an entire core of power, in production I would run many workers about 4-8 per core with different weight factors. This means if I had a server with 32 workers to handle broadcasts at 15 slots per worker, I would allow such if in idle stances but if the server grows in use at say 80-90% overall I would restart workers and re-route users to a new server immediately.

The overall is that all servers will sit around 50-80% usage depending on session size.

I’ll never know if a room will be 10 viewers one minute and 50 the next minute, I just prepare or find space for the users and restart workers if necessary to expand stream range.

Zaid shared some good topics, really follow those and whatever you find of use, not single way of doing this.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 10, 2022, 9:45am UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/13 "2022-12-10T09:45:17Z")

</div>

Thank you so much, this helped me a lot, kudos!  
“restart workers and re-route users to a new server immediately.”  
This is a very bold idea. I also had this idea, but I gave up for a moment and didn’t practice it, because I don’t know how much impact it will have on users. How does the user feel when the worker restarts? Is it a momentary thing (basically imperceptible), or will all videos stop for a while?

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [December 10, 2022, 10:22am UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/14 "2022-12-10T10:22:59Z")

</div>

Videos will stop for a while like 2, 3 seconds, it depends. You can use loader in the video player or user profile picture just like zoom to improve the UX, for video it doesn’t matter, but for audio if it takes more than 2, 3 seconds then user will surely notice it. But in some scenarios this will be totally inevitable so this is all ok at the end. The better your scalability system calculations are the lesser will be impact of it on video/audio start stop problem.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 10, 2022, 11:07am UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/15 "2022-12-10T11:07:13Z")

</div>

I understand now.  
When a Worker is about to exceed our expected load suddenly, this solution can be used as the last barrier of our various expansion solutions to ensure that a Worker that is about to exceed the load will not stop the service. Of course, the premise is that we have made resource planning according to various situations.  
Thank you all.

---

<div class="post-metadata">

**Author:** ![BronzedBroth](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BronzedBroth](https://mediasoup.discourse.group/u/BronzedBroth)\
**Post date:** [December 10, 2022, 1:43pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/16 "2022-12-10T13:43:08Z")

</div>

> [@javenwong](#):
>
> This is a very bold idea. I also had this idea, but I gave up for a moment and didn’t practice it, because I don’t know how much impact it will have on users.

An amazing impact, not only can you correct loads when a room becomes massive or returns to small sizing, you can actively stop network attacks and in theory never be put offline. Users won’t notice much of this outside a 1-3 second pause for whomever was on the selected worker while another is found.

If users are experiencing network lag, they’re happier to see I can navigate them to different servers and still scale.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 10, 2022, 2:23pm UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/17 "2022-12-10T14:23:48Z")

</div>

That’s right, thanks for the pointer, I’ll apply it to my extension model. Once I’ve finished the preliminary model, I’ll come back to share and discuss it.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 16, 2022, 5:42am UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/18 "2022-12-16T05:42:08Z")

</div>

> [@zaidiqbal](#):
>
> Router have no consumer limit, it is worker which have the limitation. \> Now 500 is for a normal CPU it differse between machines so if you have a heavy machine then you can support more than 500 per worker.
> 
> > Lets assume it is 500.
> 
> The other thing is 500 is sum of producers + consumers, not 100% sure about it. But producer do take around same cpu as the producer takes.
> 
> As for question 2 on router 1 you will have 600 consumers after piping.

I still have a doubt here, I don’t know what is the reason for the worker restriction.  
mediasoup official said: “A Worker represents a mediasoup C++ subprocess that runs in a single CPU core.”  
and : "Depending on the needed capability, the server side application using mediasoup should launch as many workers as required (no more than the number of CPU cores in the host) and distribute “rooms” (mediasoup routers) across them.”

Does it mean that if my server has 4vCPUs and I only create one worker, even if this worker exceeds the load (500), then there are still 3vCPUs idle?

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [December 16, 2022, 6:31am UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/19 "2022-12-16T06:31:49Z")

</div>

Yes one worker can’t go beyond one core. To fully utilise the CPU, you must create multiple workers, recommended is to not open more workers than the number of cores in CPU but you can open more workers than the number of cores but it is not recommended as if not used properly that will trigger the race condition among the worker processes causing problems.

So when you see the worker is getting close to its limit then open another worker and distribute the rooms between them as mentioned in docs.

---

<div class="post-metadata">

**Author:** ![javenwong](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@javenwong](https://mediasoup.discourse.group/u/javenwong)\
**Post date:** [December 16, 2022, 6:36am UTC](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766/20 "2022-12-16T06:36:13Z")

</div>

I understand now, thank you! 🙂

[Next page](https://mediasoup.discourse.group/t/about-single-router-consumers-limit-and-pipetorouter/4766.md?page=2)
