This query is related to more of Clustering of workers rather than mediasoup.
So here it is, Nodejs runs in single thread and to take advantage of all of its cores we can use the clustering of workers. Since we use mediasoup.createWorker() api to create a worker and we create as many workers as the length of the CPU cores. Does the createWorker() API internally do the clustering of workers so the number of threads running the server would be equal to the number of workers?
What do you mean with âclustering of workersâ? Do you mean âmediasoup Workerâ or Node Workers?
mediasoup does not launch N threads but N mediasoup-worker subprocesses. The OS is the one of running each subprocess in the available CPU cores. We cannot decide that.
I wanted to have cluster of node workers so that the applicationâs performance would improve a lot if more threads are spawn, i was assuming when a mediasoup worker is created it internally does the cluster fork operation⊠Now, i believe that PM2 would solve everything for me.
mediasoup does not deal with that. You can use a single Node thread or many threads (Workers) and call mediasoup.createWorker() in each. That will work.
You can do both. In theory a single Node process/worker should be enough but if your app does a lot of work in Node you may be different Node processes.
If you run the project via PM2 itâll help if unexpected crashes happen with your code. If youâre trying to utilize cluster youâll mess things upâŠLong story short, you may fork the application multiple times till you have reached core-level as long as it has a means of signaling for either process running.
Your best bet is to utilize the workers via mediasoup to not re-run your code like that and rely on master to instruct routes/workers. Been there and itâs not ideal, for a 64 core machine thatâs 64 more concurrent connections not needed. Cheers.