# Mediasoup v2 worker using single core of cpu

**URL:** <https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803>\
**Category:** mediasoup libraries\
**Created:** [May 19, 2021, 1:24am UTC](https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803 "2021-05-19T01:24:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![savsoft](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@savsoft](https://mediasoup.discourse.group/u/savsoft)\
**Post date:** [May 19, 2021, 1:24am UTC](https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803/1 "2021-05-19T01:24:51Z")

</div>

I am using mediasoup v2 library with 4 core cpu and 8 GB Ram.  
I found that when concurrent users increase then cpu usage not exceed 25%-28% but facing issue to serve consumer to more users.  
First i thought server side bandwidth issue but that i tested server has sufficient bandwidth.

Is there any method i can use full resources of server?  
In v3 it is possible but not found anything for v2.

---

<div class="post-metadata">

**Author:** ![savsoft](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@savsoft](https://mediasoup.discourse.group/u/savsoft)\
**Post date:** [May 19, 2021, 1:30am UTC](https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803/2 "2021-05-19T01:30:32Z")

</div>

in config i am using this parameters to define mediasoup.

```auto
const mediaServer = mediasoup.Server({
  numWorkers: null, // Use as many CPUs as available.
  logLevel: 'warn',
  logTags: [
      'info',
      'ice',
      'dtls',
      'rtp',
      'srtp',
      'rtcp',
      'rbe',
      'rtx'
    ],
  rtcIPv4: true,
  rtcIPv6: true,
  rtcAnnouncedIPv4: null,
  rtcAnnouncedIPv6: null,
  rtcMinPort: 40000,
  rtcMaxPort: 49999
});

 room = mediaServer.Room(config.mediasoup.mediaCodecs);
 

```

I noticed in mediaServer.Room we can pass second argument **workerIdx**  
workerIdx is number from 0 to (no. of cores -1)  
it means one room can only use one worker.  
does it creates limitation ?

---

<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:** [May 25, 2021, 2:22am UTC](https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803/3 "2021-05-25T02:22:16Z")

</div>

Very difficult to utilize things 100% and not crash,

I’d not get into the habit of sharing assigning workers to rooms unless it were some kind of premium/dedicated addon server for the room. Due to costs and all sorts it’d be more ideal to just share 100 cores with 60 rooms than 240cores dedicated. Fact here is rooms can sit idle most hours of the day and use up nothing. Don’t be cheap but could cut lot of expenses and solve major issues sharing the wealth.

A fun problem that will hurt most site owners too is legitimately having entire rooms crash, few users dropping is acceptable but anything more than that is too much so having more servers is ideal but really your call?

---

<div class="post-metadata">

**Author:** ![danisharora099](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/danisharora099/32/780_2.png) [@danisharora099](https://mediasoup.discourse.group/u/danisharora099)\
**Post date:** [May 26, 2021, 6:52am UTC](https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803/4 "2021-05-26T06:52:20Z")

</div>

Yes. In the demo code, one room runs on one worker.

This is where pipeToRouter() comes in - it will allow one room to utilise all available workers.  
Optimising CPUs internally.

You can event extend pipeToRouter() to setup pipelines between different machines (and their workers), and not just the primary machine.

---

<div class="post-metadata">

**Author:** ![savsoft](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@savsoft](https://mediasoup.discourse.group/u/savsoft)\
**Post date:** [May 26, 2021, 7:55am UTC](https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803/5 "2021-05-26T07:55:35Z")

</div>

unfortunately v2 doesn’t have this function

---

<div class="post-metadata">

**Author:** ![bwoodlt](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/bwoodlt/32/626_2.png) [@bwoodlt](https://mediasoup.discourse.group/u/bwoodlt)\
**Post date:** [June 22, 2021, 6:32am UTC](https://mediasoup.discourse.group/t/mediasoup-v2-worker-using-single-core-of-cpu/2803/6 "2021-06-22T06:32:58Z")

</div>

@danisharora099 have you implemented this before? Have any github gist of this solution?
