# Rust Mediasoup Threads

**URL:** <https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843>\
**Category:** mediasoup libraries\
**Created:** [January 23, 2022, 12:33pm UTC](https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843 "2022-01-23T12:33:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason-shen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jason-shen/32/1419_2.png) [@jason-shen](https://mediasoup.discourse.group/u/jason-shen)\
**Post date:** [January 23, 2022, 12:33pm UTC](https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843/1 "2022-01-23T12:33:57Z")

</div>

Hi

just a quick question regarding to the rust mediasoup, i see the approach in the example, it creates a new worker per router, is that the most efficiency way to do so in the rust mediasoup?  
compare with the typescript version there are differences, as the typescript version we would create workers per our cpu cores, then randomly use worker on creation, so yeah just to verify on the rust approach

cheer

any advice would be great

thanks advance

---

<div class="post-metadata">

**Author:** ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)\
**Post date:** [January 23, 2022, 1:25pm UTC](https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843/2 "2022-01-23T13:25:35Z")

</div>

It is very similar, in both cases 1 worker means 1 thread (CPU core). That doesn’t change between Rust and TypeScript.

You can certainly use the same approach with pool of workers if you want in Rust too.

There might be cases where you want to have multiple routers in the same worker, but I found that one router per worker is a simple rule of thumb that works well and is easy to manage.

---

<div class="post-metadata">

**Author:** ![jason-shen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jason-shen/32/1419_2.png) [@jason-shen](https://mediasoup.discourse.group/u/jason-shen)\
**Post date:** [January 23, 2022, 1:30pm UTC](https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843/3 "2022-01-23T13:30:12Z")

</div>

but one issue though if spinning up worker per router(agree on the easy to manage), if say the cpu only has 4 cores, wouldn’t that limit only having 4 routers if using this approach, but i also see rust uses os thread so the limit shouldn’t be just 4 please correct me if i am wrong on this

---

<div class="post-metadata">

**Author:** ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)\
**Post date:** [January 23, 2022, 1:36pm UTC](https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843/4 "2022-01-23T13:36:59Z")

</div>

You can use any number of workers on any number of CPUs in both TypeScript and Rust. Worker doesn’t use the whole CPU core unless needed, so you can have 20 workers on dual-core CPU without issues.

Whether worker is running in a thread or process is irrelevant here for the most part.

---

<div class="post-metadata">

**Author:** ![jason-shen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jason-shen/32/1419_2.png) [@jason-shen](https://mediasoup.discourse.group/u/jason-shen)\
**Post date:** [January 23, 2022, 1:38pm UTC](https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843/5 "2022-01-23T13:38:21Z")

</div>

ok great that clears up my concerns, cheers for your help appreciated !

---

<div class="post-metadata">

**Author:** ![piranna](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/piranna/32/934_2.png) [@piranna](https://mediasoup.discourse.group/u/piranna)\
**Post date:** [January 24, 2022, 8:31am UTC](https://mediasoup.discourse.group/t/rust-mediasoup-threads/3843/6 "2022-01-24T08:31:05Z")

</div>

> [@nazar-pc](#):
>
> There might be cases where you want to have multiple routers in the same worker, but I found that one router per worker is a simple rule of thumb that works well and is easy to manage.

So, are `Router` objects inside a Worker are just to group Transports, Producers and Consumers? A helper for application logic to provide a security mechanism like trying to access Producers from another Router where we don’t have access to?
