webrtcbandwidthvideo-conferencingcoturnrfc5766turnserver

How to calculate TURN server bandwidth for webrtc?


I have developed simple many to many video conferencing website using webrtc for that i need to configure TURN server. I am confused about choosing bandwidth size.

Maximum 500kbps of data will be sent by single user. Maximum participants will be 300. Maximum time per conference is about 200min and maximum host at a time is about 200.

I referred in Google nearly 80% - 85% we don't need TURN server.

For this how much bandwidth i need? Does simple coturn server will for this? If not where should i buy Turn server or is it possible to make own TURN server with this configuration.


Solution

  • First of all, WebRTC requires peer to peer connection between every single participant. If your use case has 300 participants in each session/room, each participant will have to upload/download 500kbps data from every other 299 participants, which is substantial network traffic. AFAIK, even google limits google meet/hangout video calls to 25 participants which they use WebRTC under the hood.

    I doubt you want to build video conference system with WebRTC when there are 100+ participants, but still, I will help you get the numbers that you want for now, and explain why it probably won't be realistic at the end of the answer.

    Using your numbers, let's assume that 20% of the users (Group A) will require TURN server due to their network setup (e.g. behind NAT), while other 80% of users (Group B) will be able to establish direct peer to peer connections to each other.

    1. User in group A will need TURN to connect with another user in group A
    2. User in group A will need TURN to connect with another user in group B
    3. User in group B will need TURN to connect with another user in group A
    4. User in group B will not need TURN to connect with user in group A, and direct peer-to-peer connection will work in this case.

    Using your numbers, if 80% of users belong to group B that means that chance of #4 happening is about 64%. (80% * 80%). So 64% of the network traffic will be peer-to-peer connections which do not require TURN, while the rest 36% of the traffic will need TURN server to relay video data.

    One user will need to connect to 299 other users where 36% of the connections will get routed through TURN. That translate to about 107 connections routed through TURN. For the sake of simplicity, let's say each user's 100 out of 299 connections need TURN relay.

    You said maximum 500kbps data is sent by each user. Since each user need to send the video to 100 other users through TURN, this translates to around 50000kbps or 50Mbps. So in average, each user consumes 50Mbps network throughput through TURN. (and another 100Mbps for direct p2p connections)

    Since there are 300 users/participants in each session, you multiply 50Mbps by 300, which gives you 15000Mbps or 15Gbps or 15Gb/s which is total TURN traffic per second used by all participants.

    You said maximum conference length is 200 minutes, so total traffic amount exchanged during 200 minutes session will be 15Gb/s * 60s/m * 200 = 180000 Gb = 22500 GB

    FYI, cloud providers charge about $0.07/GB for network traffic, so your full 200 min session which requires up to 22500 GB network traffic can cost $1575.

    WebRTC is ideal for use cases where number of participants in a room/session is small due to its nature of each participant having to connect to all other participants. Its # of connections required increases at the rate of O(n^2) where n is number of participants.

    You might want to look into using SFU/MFU or adjusting your numbers to make it more realistic. (e.g. Do you really need 300 participants to all share their video at the same time?) Not to mention there won't be many users who can support 150Mbps upstream & 150Mbps downstream network.