Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High CPU usage with RTCPeerConnections

I have the following setup:

enter image description here

The idea is that Computer A captures a single local MediaStream from Cam 1 using getUserMedia. Two RTCPeerConnections are then created locally - R5Outbound and R6Outbound. Both Computer B and Computer C create their own inbound RTCPeerConnections to capture this stream.

I'm noticing that Computer A - with an i7 CPU - is running hot and occasionally crashes my instance of Chrome (60) with the below setup after hitting 95%+ CPU.

After some reading I'm starting to think that I'm creating too many instances of RTCPeerConnection here; though with multiple streams originating from a single device in some cases, I'm a bit confused about how to properly create and manage my RTCPeerConnections. My question is - given the above topology and the requirement that all computers need to see all streams (though some computers may not have a stream to share), what RTCPeerConnections should be created?

I should note that mesh is required for now; business constraints have us eager but unable to use an MCU or SFU architecture.

Some answers to questions:

How much RAM and disk space is available at Computer A?

16GB / >1TB SSD.

Why are two outbound streams necessary at Computer A? What is the purpose of two outbound streams?

Computer A has two cameras attached. One stream per camera is captured. Each stream is then shared with each other computer.

Do you clone the original stream to supply the MediaStream for R5Outbound and R6Outbound?

Both R5.O and R6.O use the same MediaStream instance (I say that with 80% confidence - need to check my code and post back).

like image 998
SB2055 Avatar asked Nov 07 '22 18:11

SB2055


1 Answers

For a mesh network, you've got the right idea. The problem you're experiencing is that transferring MediaStreams across peer connections is an expensive operation. In a mesh network, for every peer connection you make you are uploading your MediaStream and downloading a MediaStream. You can optimize this with an intermediary server that all clients talk to (instead of talking directly to each other). Here is a video for more information on what that looks like: https://vimeo.com/198382135

like image 160
Andrew Sinner Avatar answered Nov 14 '22 23:11

Andrew Sinner