iOS multiple connections

239 views
Skip to first unread message

Jimmy C

unread,
Dec 10, 2020, 7:43:06 AM12/10/20
to discuss-webrtc
Hello All,

For my project I want to establish multiple WebRTC data channel connections (about 70-100 connections) to different servers from an iOS device. Is this a reasonable use case for using WebRTC? I am using the WebRTC.framework and not over a browser.

I also noticed that when I try to create a multiple peer connections simultaneously, the following function calls would sometimes not return and just hangs, kind of like a deadlock situation:

RTCPeerConnection.add(candidateMessage:)
RTCPeerConnection.setRemoveDescription(description:, completionHandler:)
RTCPeerConnection.close()

However, when I try to connect one after another (instead of simultaneously), everything is fine. Does the WebRTC library spawn multiple threads when trying to create a peer connection? It also seems like each open connection uses about 1-2% CPU constantly on iOS. Thus with 100 connections, I am seeing 100% CPU usage constantly, even when there is no traffic. Android on the other hand doesn't seem to have this issue. Once connected, the CPU drops down to zero when there is no traffic. Is this expected?

Any insight on this would be great, thanks!

Jimmy C

unread,
Dec 11, 2020, 8:52:32 PM12/11/20
to discuss-webrtc
So I did some testing. Seems like for every ice server I add, the WebRTC spawns 10 threads. I have 4 ice servers and thus for each connection it is creating 40 threads. If I set the iceCandidatePool in the config to any value that is not zero, the number of threads skyrocket. Once 1024 threads is reached, the app crashes. Any idea how come WebRTC creates so many threads? 

The reason why I have this problem is because I am making many connections. If I just have one connection, the multiple threads is not an issue.

Also I want to note that once I call peerConnection.close(), all the threads are properly removed. So looks like there isn't any rogue threads, just a lot of threads running.

Reply all
Reply to author
Forward
0 new messages